js:
//铵enter键,阻止提交订单
function doClick(event) {
// if ($.trim($('#' + buttonId + '').val()) == '') {
// shorError();
// return;
// }
var key;
if (window.event)
key = window.event.keyCode; //IE
else
key = event.which; //firefox
if (key == 13) {
// if ($.trim($('#btnVerificationCode').val()) == '') {
// shorError();
// }
try {
if (window.event) {//ie
window.event.keyCode = 0
window.event.returnValue = false;
}
else {//firefox
return false;
}
}
catch (ex) {
}
}
}html:
<input id="btnVerificationCode" type="text" value="" style="width: 45px;"
name="checkcode" onkeypress="return doClick(event);"
maxlength="4" />
本文介绍了一种使用JavaScript阻止用户按下Enter键时默认提交表单的方法。通过监听按键事件并判断是否为Enter键,实现取消默认行为,适用于IE和Firefox等浏览器。
8824

被折叠的 条评论
为什么被折叠?



