i have this code :
我有这个代码:
<li class="rtLI rtFirst rtLast" >
<div class="Root"><div class="rtTop" onclick="changeActiveView('1')" >
<span class="rtSp"></span>
<span class="rtPlus" onclick="ExpandRoot(this,'SubMenu_1','RootElemUl')"></span>
<span class='rtIn'>
<img src='img1.png' />
<span class='labl' >Title</span>
</span>
</div></div>
</li>
when i click on the span with classrtPlus
ChangeActiveView is automatically executed as well how can i prevent that ?
当我用classrtPlus单击span时,ChangeActiveView会自动执行,我该如何防止?
1 个解决方案
#1
1
event.stopPropagation();
Prevents further propagation of the current event.
防止进一步传播当前事件。
http://devdocs.io/dom/event.stoppropagation
Put that line of JS in the function you want to work, and it will prevent the event from bubbling upward through the DOM and reaching the parent element (and triggering the parent's listener).
将该行JS放在您想要使用的函数中,它将阻止事件通过DOM向上冒泡并到达父元素(并触发父元素的侦听器)。
#1
1
event.stopPropagation();
Prevents further propagation of the current event.
防止进一步传播当前事件。
http://devdocs.io/dom/event.stoppropagation
Put that line of JS in the function you want to work, and it will prevent the event from bubbling upward through the DOM and reaching the parent element (and triggering the parent's listener).
将该行JS放在您想要使用的函数中,它将阻止事件通过DOM向上冒泡并到达父元素(并触发父元素的侦听器)。