admin管理员组文章数量:1356775
using chrome 15 on osx 10.6.8
When adding event listeners, I've found that putting preventDefault
in when a keypress
event is used, I get mas issues.
Take a look here
unment the line with event.preventDefault();
on it and you'll see the keypress event stops working. what's the deal?
using chrome 15 on osx 10.6.8
When adding event listeners, I've found that putting preventDefault
in when a keypress
event is used, I get mas issues.
Take a look here
unment the line with event.preventDefault();
on it and you'll see the keypress event stops working. what's the deal?
1 Answer
Reset to default 8preventDefault()
does exactly what it's supposed to. It stops the default action of the key. If you want the default action of the key, then don't call it.
In both Chrome and Firefox, I see repeated keypresses, even when preventDefault()
is unmented from your fiddle. Perhaps you were losing focus.
It would help us know what to suggest in it's place if you describe more about what you're trying to acplish.
In your jsFiddle, you are listening to keys at the document level. By the time the keystrokes propogate up to the document, they have already been processed by the individual objects that they are targetted at. If you want to intercept and prevent keys from being processed, you have to process them in event handlers on the objects they originally are targetted at. You can't prevent default on keys from the document level. In this jsFiddle where I intercept the keystrokes on the first object they go to, you can see that they are entirely blocked. You may also want to be aware that cross-browser behavior is not perfect in this regard as there are some browser differences you can see here.
本文标签: eventsjavascript preventdefault kills keypressStack Overflow
版权声明:本文标题:events - javascript preventdefault kills keypress - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743978061a2570958.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论