如何在keydown处理程序中停止按键事件。
答案 0 :(得分:3)
即使从keydown你也无法阻止按键......它们都是非常独立的事件。你可以做的是在阅读角色后取消keydown / keypress。这就是我只允许通过键入文本框(jQuery)
来允许字母和数字 urlBox.keypress(function(e){
if(e.which == 13 || e.which == 8 || e.which == 0) return true;
if(48 <= e.which && e.which <= 57) return true;
if(65 <= e.which && e.which <= 90) return true;
if(97 <= e.which && e.which <= 122) return true;
return false;
});