标签:
按下回车触发点击事件:
1 $(function(){ 2 $("#btn1").on("click",function(){ 3 console.log("clicked!") 4 }); 5 6 $("#input1").keydown(function(e){ 7 var keynum; 8 9 if(window.event) // IE 10 { 11 keynum = e.keyCode; //现在IE keyCode和which都支持 12 } 13 else if(e.which) // Netscape/Firefox/Opera 14 { 15 keynum = e.which; 16 } 17 if (keynum == 13) { 18 $("#btn1").click();//回车触发 19 } 20 21 }); 22 })
accesskey属性,设置选择页面上元素的快捷键,windows下同时按下 Alt+s 等于点击提交按钮:
<!DOCTYPE html> <html> <head> <title>Key Down Test</title> </head> <body> <input id="input1" type="text" /> <button id="btn1" accesskey="s">提交</button> </body> <script src="js_lib/jquery.min.js" type="text/javascript"></script> <script src="keydown/keydown.js" type="text/javascript"></script> </html>
标签:
原文地址:http://www.cnblogs.com/yongwangzhiqian/p/5828678.html