好吧,我有热键工作只是不能让它停止
$(document).keypress(function(e){
if(e.which == 13){
//Enter key is press do what you want
}
else if(e.which == 67 || e.which == 99){
//C key is press do what you want
window.location.href = "/html/credits.php";
}
else if(e.which == 32){
alert("Space pressed");
}
});
$("input.registerform").keypress(function(e){
e.stopPropagation(); });
这是我必须让它停止的,我的输入表单的类是“registerform bgcolor2”,但它不能与“input.registerform”一起使用,也不能与“input.registerform bgcolor2”一起使用我尝试向它添加一个 ID使用注册表格作为 ID 也不起作用:/
它是由我的 AJAX 引起的吗?还是我在这里遗漏了什么?
(抱歉,我重新发布了这个只是创建了一个新帐户,无法找到我的旧问题 >.<)
最佳答案
我知道,由于您将事件监听器附加到文档对象,所有输入接受元素(例如文本字段、选择等)都将处理热键,因此失去了它们的正常行为。
看看line 44在jquery.hotkeys插入。它在初始化时排除所有输入接受元素。
附言也许这个插件作为一个整体对您的任务很有用。
关键是检查事件是否来自接受文本的输入。
# only bind event to text-accepting elements, if they have been
# explicitly selected
# if your event variable happens to be called e, please adjust accordingly
if ( this !== event.target &&
( /textarea|select/i.test( event.target.nodeName ) ||
event.target.type === "text") ) {
return;
}
按照您现在的代码,您需要在绑定(bind)到按键事件的匿名函数的开头插入此代码段。
关于Javascript -> 热键 -> 禁用输入字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7024748/