【问题标题】:jQuery: triggering (mousemove or "keypressed")jQuery:触发(鼠标移动或“按键”)
【发布时间】:2012-11-19 07:42:10
【问题描述】:

我已经阅读了一些关于触发 mousemove 任何键被按下的答案,但我仍然不确定,将两个事件结合起来的最佳方法是什么 - mousemove 和按下任意键二合一。

最好的修改方法是什么

$(document).mousemove(function ()
{
  alert('The mouse was touched');
}

$(document).<???>(function ()
{
  alert('The mouse was touched or any key pressed');
}

【问题讨论】:

    标签: jquery events keypress mousemove onkeypress


    【解决方案1】:

    你可以使用.on()

    $(document).on( "mousemove keypress", function () {
     code
    });
    

    【讨论】:

      【解决方案2】:

      拥有 3 个函数可能是最好的选择。

      $(document).mousemove(movePressed()); //calls function
      $(document).keypress(movePressed()); //calls same function
      
      function movePressed(){//do whatever you want when mousemove or keypressed}
      

      【讨论】:

      • 没有keypressed 事件并且您没有注册处理程序,您正在调用它们,您应该删除()
      • 是的,那是keypress 而不是keypressed
      • 哦,哎呀,对不起,伙计,我的错。
      猜你喜欢
      • 1970-01-01
      • 2014-06-19
      • 2019-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-14
      相关资源
      最近更新 更多