<div class="subitems">
<ul>
<li id="China"></li>
<li id="India">
India
<div id="subitems">
<ul>
<li id="India/Sub Item 1">Sub Item 1</li>
<li id="India/Sub Item 2">Sub Item 2</li>
<li id="India/Sub Item 3">Sub Item 3</li>
<li class="additem">+</li>
</ul>
</div>
</li>
<li>id="Austria"</li>
</ul>
</div>
就像你期望的那样:
$('.subitems ul li').mousedown(function (event) {
if (event.which == 3) {
alert('right mouse clicked');
}
});
是点击India/SubItem1
时,印度<li>
和India/SubItem1
<li>
都会被解雇,而我只想要India/SubItem1
被解雇。当点击印度时,我只想让印度开火。
我该如何解决这个问题?
答案 0 :(得分:1)
event.stopPropagation();
将阻止事件冒泡DOM:
$('.subitems ul li').mousedown(function (event) {
event.stopPropagation();
if (event.which == 3) {
alert('right mouse clicked');
}
});