Jquery mousedown vs click [英] Jquery mousedown vs click
问题描述
今天我发现了一些让我感到困惑的事情。
我只是试图通过jquery隐藏s.th ...首先我尝试使用这个
today I discovered something that was quite confusing for me. I just tried to hide s.th via jquery... first I tried to use this
$(".specificdiv li:nth-child(3)").click(function(){
$(".anotherdiv").hide();
})
....但它不起作用。
....but it does not work.
经过一段时间我试过这样:
After a time I tried it this way:
$(".specificdiv li:nth-child(3)").mousedown(function(){
$(".anotherdiv").hide();
})
任何人都可以解释为什么mousedown工作而不是点击?
很高兴找到
Can anyone explain me why mousedown works instead of click? Would be great to find out
编辑
编辑了另一个。
推荐答案
可能的原因:
- 事件
mousedown
在点击
之前执行,所以先到先得。 - 该元素可能已经有一个
点击
事件,这可以防止这种情况发生,比如说函数首先执行并且它有一个在其中返回false
语句。
- The event
mousedown
executes beforeclick
, so first come first serve. - The element might have already a
click
event, which prevents this from happening, say that function executes first and it has areturn false
statement in it.
现在因为你正在使用 mousedown
,没有为此元素分配,它没有任何冲突。这个可能是的原因,因为您没有发布完整的代码。随意纠正。 :)
Now since you are using mousedown
, which is not assigned for this element, it doesn't have any conflicts. This may be a reason, because you didn't post the full code. Feel free to correct. :)
在较小的音符上,你有 $(。anotherdiv)。hide();
in第一个代码和 $(。another)。hide();
在第二个代码中,缺少 div
在课堂里。这是一个问题吗?
On a smaller note, you have $(".anotherdiv").hide();
in the first code and $(".another").hide();
in the second code, missing the div
in the class. Is that a problem?
这篇关于Jquery mousedown vs click的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!