<div class="codetitle"> <span><a style="CURSOR: pointer" data="56486" class="copybut" id="copybut56486" onclick="doCopy('code56486')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code56486"> <br><textarea onkeydown="keyHanlder(event)"> <br></textarea> <br><script> <BR>function keyHanlder(e){ <BR>if(e.ctrlKey&&e.keyCode==13){ <BR>alert('"Ctrl+Enter"'); <BR>if(e.preventDefault)e.preventDefault(); <BR>else e.returnValue=false; <BR>} <BR>} <BR></script> <br> </div> <br><br>非IE浏览器调用函数会自动返回参数event,通过它可以获取键盘 <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="48200" class="copybut" id="copybut48200" onclick="doCopy('code48200')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code48200"> <br><script language="JavaScript"> <BR><!-- <BR>function hotkey(e) <BR>{ <BR>//判断浏览器 <BR>var ex = navigator.appName; <BR>var a = ex=='Microsoft Internet Explorer'? window.event.keyCode : e.which; <BR>alert(a); <BR>switch(a){ <BR>case 83: <BR>window.open('Myhomepage/search.htm','show') <BR>break; <BR>case 70: <BR>window.open('Myhomepage/favorite.htm','show') <BR>break; <BR>} <BR>}// end hotkey <BR>document.onkeydown = hotkey; //当onkeydown 事件发生时调用hotkey函数 <BR>//--> <BR></script> <br> </div>