mousedown和click in jQuery之间的区别 [英] Difference between mousedown and click in jquery

查看:106
本文介绍了mousedown和click in jQuery之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习jquery中的事件.在实施它们时,我遇到了一个疑问. mousedown()和click()事件有什么区别.而我应该在什么条件下使用哪个事件??

I am learning events in jquery. While implementing them i came across a doubt. What is the difference between mousedown() and click() event. And which event should i use at what condition.?

例如: 这两个事件在以下代码中执行相同的任务:

For example: Both the events perform the same task in the below code:

$("#p1").mousedown(function(){
  alert("Mouse down over p1!");
});


$("#p1").click(function(){
  alert("Mouse down over p1!");
});

两者的表现相同.有人可以澄清两者之间的差异.如果相同,我该选择哪一个?

Both perform the same.Can someone clarify the difference. If same, which should i prefer?.

推荐答案

onMouseDown将在按下向左或向右(或中间)时触发.同样,onMouseUp将在释放任何按钮时触发. onMouseDown会触发,即使在对象上单击鼠标然后将其移开,而onMouseUp也会触发,如果您在其他位置单击并按住按钮,然后将其释放到对象上方.

onMouseDown will trigger when either the left or right (or middle) is pressed. Similarly, onMouseUp will trigger when any button is released. onMouseDown will trigger even when the mouse is clicked on the object then moved off of it, while onMouseUp will trigger if you click and hold the button elsewhere, then release it above the object.

onClick仅当在同一对象上按下并释放鼠标左键时才会触发.如果您关心顺序,则如果同一对象设置了所有3个事件,则分别为onMouseDownonMouseUponClick.每个偶数只能触发一次.

onClick will only trigger when the left mouse button is pressed and released on the same object. In case you care about order, if the same object has all 3 events set, it's onMouseDown, onMouseUp, then onClick. Each even should only trigger once though.

详细信息:

http://api.jquery.com/click/
http://api.jquery.com/mouseup/
http://api.jquery.com/mousedown/

http://api.jquery.com/click/
http://api.jquery.com/mouseup/
http://api.jquery.com/mousedown/

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆