简体   繁体   English

如何判断是单击鼠标还是按下键盘

[英]how to tell if mouse is click or keyboard is press

I wanted to check if the mouse is click or key is press. 我想检查鼠标是单击还是按下键。
like if i click on something i can set Timer back to zero. 就像我单击某些东西一样,可以将Timer设置回零。 or press any key, do the same. 或按任意键,执行相同操作。

Using jQuery, bind keypress and click events to the document: 使用jQuery,将keypressclick事件绑定到文档:

$(document).on('keypress click', function(e) {
    //reset timer to 0
});

Take a read of the API doc for .on() . 阅读.on()API文档

Use the keypress and click events given by jQuery library. 使用jQuery库提供的按键和单击事件。 Your event should be linked with an element in the DOM 您的事件应与DOM中的元素链接

Reference 参考

http://api.jquery.com/click/ http://api.jquery.com/click/

http://api.jquery.com/keypress/ http://api.jquery.com/keypress/

如果您希望在单个功能中实现这两个功能,则可以只使用提交事件侦听器,该事件侦听器涵盖了鼠标单击和键盘输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM