jQuery:如何捕获keydown +鼠标点击事件?

时间:2010-10-06 12:40:05

标签: keypress keydown jquery

我有一个div元素。当按下alt键(keyCode = 17)时,我需要鼠标点击div

这是我必须抓住关键的新闻:

// Html
<div id="targetDiv">I want to put a ding in the universe.</div>
// Java-script
$(document).ready(function(){
    $(window).bind('keydown', function(event){
        if ( 17 == event.keyCode ) {
           // How to catch mouse click on $('#targetDiv') ?
        }
    });
});

按下alt键时如何捕捉鼠标点击div?

1 个答案:

答案 0 :(得分:25)

您可以查看.altKey property,例如:

$(function() {
  $("#targetDiv").click(function(event) {
    if (event.altKey) {
       //do something, alt was down when clicked
    }
  });
});

You can test it out here