为什么我的警报不止一次显示? [英] Why is my alert showing more than once?
本文介绍了为什么我的警报不止一次显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个jQuery代码:
I have this jQuery code:
$("div.note a").live("click", function(e) {
e.preventDefault();
alert('test');
});
<div id="note_list">
<div class="note">
Text 1
<a href="">X</a>
</div>
<div class="note">
Text 2
<a href="">X</a>
</div>
<div class="note">
Text 3
<a href="">X</a>
</div>
</div>
有人能告诉我为什么警报显示3次?它适用于Chrome,但不适用于Firefox。
Could someone tell me why the alert shows 3 times? It works fine in Chrome but not in Firefox.
推荐答案
它被称为onetime,在您的情况下,您可以通过以下方式停止多个事件调用 e.stopImmediatePropagation();
It is called onetime, in your case you can stop multiple event call by e.stopImmediatePropagation();
$("div.note a").live("click", function(e) {
e.stopImmediatePropagation();
e.preventDefault();
alert('test');
});
这篇关于为什么我的警报不止一次显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文