我正在尝试使用keydown(enter)提交表单,并通过所需的功能将其发送。但是当我按下Enter键时,它表现出类似于HTML按钮类型为Submit的行为。 这是我的BackboneJS代码:
$view.UserProfile_ConfirmPhoneNumber = Backbone.View.extend({
el: "#confirmPhoneNumberForm",
events: {
"click #send-confirm-phone-number-code": "sendConfirmPhoneNumberCode",
'keydown': 'keyAction',
},
keyAction: function (e) {
var code = e.keyCode || e.which;
if (code == 13) {
sendConfirmPhoneNumberCode();
}
},
sendConfirmPhoneNumberCode: function() {
//some code
}
这是我的html:
<form class="newRegister-formBox basketForm" id="confirmPhoneNumberForm" autocomplete="off">
<input type="hidden" id="returnUrl" value="@ViewBag.ReturnUrl" name="ReturnUrl">
<div class="newRegister-formBox">
<div class="formElement newRegister-input">
<i class="fa fa-key loginIcone"></i>
<input autocomplete="off" type="text" name="code" id="code" class="form-control persianDigitInput" placeholder="enter code">
</div>
<div class="newRegister-button">
<button type="button" id="send-confirm-phone-number-code" class="animateBtn greenAnimateBtn">
<i class="fa fa-check"></i>
confirm
</button>
</div>
</div>
</form>
答案 0 :(得分:1)
尝试
keyAction: function (e) {
var code = e.keyCode || e.which;
if (code == 13) {
e.preventDefault();
sendConfirmPhoneNumberCode();
return false;
}
},