Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
362 views
in Technique[技术] by (71.8m points)

keypress - jQuery: How to catch keydown + mouse click event?

I have a div element. I need to catch a mouse click on this div while alt-key (keyCode = 17) is pressed.

Here is what i've got to catch key press:

// 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') ?
        }
    });
});

How to catch mouse click on div while alt-key is pressed?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can check the .altKey property, for example:

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

You can test it out here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...