本文介绍了为表单禁用输入密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直试图在我的表单上禁用键。我拥有的代码如下所示。由于某种原因,回车键仍然触发提交。该代码在我的头部分,似乎从其他来源是正确的。
I have been trying to disable the key on my form. The code that I have is shown below. For some reason the enter key is still triggering the submit. The code is in my head section and seems to be correct from other sources.
disableEnterKey: function disableEnterKey(e){
var key;
if(window.event)
key = window.event.keyCode; //IE
else
key = e.which; //firefox
return (key != 13);
},
推荐答案
它非常smiple。这里你去
if you use jQuery, its quite smiple. Here you go
$(document).keypress(
function(event){
if (event.which == '13') {
event.preventDefault();
}
});
这篇关于为表单禁用输入密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!