按下回車時觸發事件:
第一種:當鍵盤按下回車時觸發這個不帶參數的函數
<meta http-equiv="content-type" content="text/html; charset=gb2312"/> <script type="text/javascript"> function show () { var e=window.event||arguments.callee.caller.arguments[0]; if(e.keyCode==13){ alert("你按下了回車"); } } </script> <input onkeydown="show();" value="觸發鍵盤試試">
代碼分析:window.event是獲取IE下面的事件,但是在火狐下不支持,所以加上了arguments.callee.caller.arguments[0];
第二種:這個是寫在行內式的
<input onkeydown="var e=window.event || arguments[0];if(e.keyCode==13){ alert('你按下了回車鍵,修改這里來實現你要的效果'); }" value="回車試試">