jquery禁用键盘按键
答
您不能禁用击键这样,但你可以用jQuery捕获并覆盖其行为(返回false)。下面的示例捕获输入密钥。只需将13更改为您需要禁用的任何键码。
$("input").keypress(function (evt) {
var keycode = evt.charCode || evt.keyCode;
if (keycode == 13) { //Enter key's keycode
return false;
}
});
答
处理onKeyDown
,然后preventDefault
就可以了。
答
只需添加一个OnKeyUp,Down-EventListener
到你的HTML页面,如果按下的键是要忽略你刚才preventDefault
答
您可以使用下面的插件是这样的: $('#text_input').filter_input({regex:'[a-z]'})
;
http://www.thimbleopensource.com/tutorials-snippets/jquery-plugin-filter-text-input
答
我能想到的是这样的:通过返回false你告诉浏览器不允许按下的键事件
答
我不得不关闭所有的钥匙,但
// Bind this keypress function to the html (not sure about this) or body tags of your page
$("body").keypress(function (evt) {
//Determine where the character code is coming from
var charCode = evt.charCode || evt.keyCode;
if (charCode == 13) { //Enter key's keycode, could be any other key
return false;
}
});
F11和ESC。所以我这样做了。认为这可能有助于某人。 :)
$(document).on('keydown',function(e)
{
var key = e.charCode || e.keyCode;
if(key == 122 || key == 27)
{}
else
e.preventDefault();
});
+0
其有用的,但它不工作在PrtSc屏幕,actully我想用这个没有人可以保存我的网页,甚至没有截图,如果你可以plz帮助 – sunil 2016-11-11 08:06:01
刚刚意识到会捕获输入字段。如果你想禁用整个页面,将“input”改为“body”。 – detheridge02 2012-01-10 14:54:18