Posted in Javascript onDecember 30, 2010
<textarea onkeydown="keyHanlder(event)"> </textarea> <script> function keyHanlder(e){ if(e.ctrlKey&&e.keyCode==13){ alert('"Ctrl+Enter"'); if(e.preventDefault)e.preventDefault(); else e.returnValue=false; } } </script>
非IE浏览器调用函数会自动返回参数event,通过它可以获取键盘
<SCRIPT LANGUAGE="JavaScript"> <!-- function hotkey(e) { //判断浏览器 var ex = navigator.appName; var a = ex=='Microsoft Internet Explorer'? window.event.keyCode : e.which; alert(a); switch(a){ case 83: window.open('Myhomepage/search.htm','show') break; case 70: window.open('Myhomepage/favorite.htm','show') break; } }// end hotkey document.onkeydown = hotkey; //当onkeydown 事件发生时调用hotkey函数 //--> </SCRIPT>
Javascript事件热键兼容ie|firefox
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@