問題描述
我想使用 JavaScript 和 jQuery 處理 F1-F12 鍵.
I want to handle F1-F12 keys using JavaScript and jQuery.
我不確定要避免哪些陷阱,而且我目前無法在 Internet Explorer 8、Google Chrome 和 Mozilla FireFox 3 之外的任何其他瀏覽器中測試實現.
I am not sure what pitfalls there are to avoid, and I am not currently able to test implementations in any other browsers than Internet Explorer 8, Google Chrome and Mozilla FireFox 3.
對完整的跨瀏覽器解決方案有什么建議嗎?類似于經過良好測試的 jQuery 庫,或者只是普通的 jQuery/JavaScript?
Any suggestions to a full cross-browser solution? Something like a well-tested jQuery library or maybe just vanilla jQuery/JavaScript?
推薦答案
這類問題的最佳來源是這個頁面:http://www.quirksmode.org/js/keys.html
The best source I have for this kind of question is this page: http://www.quirksmode.org/js/keys.html
他們說的是 Safari 上的鍵碼很奇怪,其他地方都一致(除了 IE 上沒有按鍵事件,但我相信 keydown 有效).
What they say is that the key codes are odd on Safari, and consistent everywhere else (except that there's no keypress event on IE, but I believe keydown works).
這篇關于使用 JavaScript 和 jQuery,跨瀏覽器處理按鍵事件 (F1-F12)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!