Javascript 点击回车后获取值
我想在按下回车键后获得输入值 我的xhtml看起来像Javascript 点击回车后获取值,javascript,angularjs,Javascript,Angularjs,我想在按下回车键后获得输入值 我的xhtml看起来像 <div class="medium-12 columns"> <input name="verificationCode" ng-enter="enteredVerificationCode()" ng-model="user.verificationCode" type="text" id="verificationC
<div class="medium-12 columns">
<input name="verificationCode" ng-enter="enteredVerificationCode()" ng-model="user.verificationCode" type="text" id="verificationCode" placeholder="Enter Verification Code Here" />
<div ng-messages="formSubmitted && signupForm.email.$error">
<div ng-message="required" class="error">Verification Code is required.</div>
</div>
</div>
}您可以将其包装在表单标记中
<form ng-submit="enteredVerificationCode()">
<div class="medium-12 columns">
<input name="verificationCode" ng-model="user.verificationCode" type="text" id="verificationCode" placeholder="Enter Verification Code Here" />
<div ng-messages="formSubmitted && signupForm.email.$error">
<div ng-message="required" class="error">Verification Code is required.</div>
</div>
</div>
</form>
需要验证码。
您可以使用来检测按键笔划,并查找enter键(13)以触发enteredVerificationCode()
函数
<input ng-keypress=keypressed($event) ng-model="verificationCode">
$scope.keypressed = function(event) {
if (event.keyCode === 13)
enteredVerificationCode()
}
$scope.keypressed=函数(事件){
如果(event.keyCode===13)
输入验证代码()
}
<input ng-keypress=keypressed($event) ng-model="verificationCode">
$scope.keypressed = function(event) {
if (event.keyCode === 13)
enteredVerificationCode()
}