技术饭
jQuery ctrl+Enter shift+Enter的判断方案
copylian
0 评论
11804 浏览
2017.02.09
jQuery中对键盘事件进行了修正
调用函数的时候传入事件即可。
通过事件的which可以找到键码
不过当有组合键的时候还需要注意一下
如ctrl+enter键,虽然都是用e.ctrlKey但是 enter键的键码不是始终为13了
在ff中 判断 ctrl+enter 是 e.ctrlKey && e.which ==13
在ie6中 判断ctrl+enter 是 e.ctrlKey && e.which ==10
示例:
$(document).keypress(function(e){ if(e.ctrlKey && e.which == 13 || e.which == 10) { $("#btn").click(); } else if (e.shiftKey && e.which==13 || e.which == 10) { $("#btnv").click(); } })

感谢你的支持,我会继续努力!

扫码打赏,感谢您的支持!
文明上网理性发言!