考虑以下事项:
<div onclick="alert('you clicked the header')" class="header">
<span onclick="alert('you clicked inside the header');">something inside the header</span>
</div>
我怎样才能让用户点击跨度时,不会触发div
的点击事件?
考虑以下事项:
<div onclick="alert('you clicked the header')" class="header">
<span onclick="alert('you clicked inside the header');">something inside the header</span>
</div>
我怎样才能让用户点击跨度时,不会触发div
的点击事件?
<span onclick="event.stopPropagation(); alert('you clicked inside the header');">something inside the header</span>
对于IE:window.event.cancelBubble = true
<span onclick="window.event.cancelBubble = true; alert('you clicked inside the header');">something inside the header</span>