Sac*_*hin 1 javascript jquery keypress keydown
我有两个选择对自己keypress和keydown.我倾向于使用,keypress因为它记录了一个事件,即使重复键,即长按键.但问题是keypress只在Firefox 中记录箭头键等特殊键.如果我想通过浏览器进行操作,那么我必须使用,keydown但是长按将被记录为单个事件.
任何帮助表示赞赏.
var pressed = null;
$(element).on('keydown', function(event) {
pressed = +new Date();
// do whatever else you need upon key down
});
$(element).on('keyup', function(event) {
var duration = +new Date() - pressed;
pressed = null;
// do whatever you need to do based on the duration of the press
});
Run Code Online (Sandbox Code Playgroud)
我把它作为练习留给你来解决对多个并发键的支持.
| 归档时间: |
|
| 查看次数: |
4407 次 |
| 最近记录: |