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();

        }         

 })

相关文章:

  • 2021-07-29
  • 2022-01-15
  • 2021-06-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-01
  • 2022-12-23
  • 2022-12-23
  • 2021-08-19
  • 2021-08-26
  • 2021-12-03
  • 2021-06-17
相关资源
相似解决方案