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
441 views
in Technique[技术] by (71.8m points)

javascript - What's the difference between 'mouseup' and 'click' events?

Using jQuery, I often like to use mousedown and mouseup events in conjunction for pushable buttons.

However, in every case I've used the mouseup event, binding the click event instead seemed to produce identical results.

Is there any substantial difference between the two methods below?

// Method 1
$('.myButton').bind('click', callback);

// Method 2
$('.myButton').bind('mouseup', callback);

Please note I'm seeking a technical explanation on the differences between using both methods. This has no relation to the question that has been flagged as a dupe: Differentiate click vs mousedown/mouseup

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

With a mouseup event, you can click somewhere else on the screen, hold down the click button, and move the pointer to your mouseup element, and then release the mouse pointer.

A click event requires the mousedown and mouseup event to happen on that element.

The normal expectation is that a click requires both the mousedown and mouseup event, so I'd recommend the click event.

From the possible duplicate, it appears that mouseup and mousedown events can also be caused by mouse buttons other than the left click button. Which is very different from what a generic user would expect.


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

...