如果按下键'H'并且鼠标移动到某个div上,我试图捕获事件。
KeyPressed和mouseMoving两者都必须为真
https://jsfiddle.net/bababalcksheep/1Loeh2pn/
码
$('#header').on("mousemove keydown", function(e) {
//only print if key 'H' is pressed and mouse is moving over $('#header')
if (e.type === 'mousemove' && e.which === 72) {
console.log('working');
}
});
答案 0 :(得分:1)
这可能对你有所帮助。
https://jsfiddle.net/1Loeh2pn/3/
$(function() {
$("#header").hover(function() {
$(document).keydown(function(e) {
if(e.which == 72){
console.log('H')
}
});
});
});