这是问题html:
<ul id="update-list">
<li class="update" onclick="window.location('some_url')">
<h2> some header </h2>
<p> some paragraph </p>
<div>
<a class="popup-link">
<span> Show Popup </span>
<span> + </span>
</a>
</div>
</li>
// this repeats n times
//...
</ul>
当我点击.popup-link
链接时,它应该只打开灯箱弹出窗口(它确实如此),但内联 onclickli
也会触发。问题是这些li
标签都是一些部分的一部分,这些部分是通过不同页面上的 ajax 获取的。所以我使用 jQuerydelegate
来绑定事件,如下所示:
$('#update-list').delegate('.popup-link', 'click', function(e){
// e.target is <span> while e.currentTarget is .popup-link
e.stopPropagation();
//console.log(e.isPropagationStopped()); this shows 'true' in console
$.popup(); // launch popup
e.preventDefault(); // or return false
});
这似乎不起作用,onclick
无论如何内联都会触发。我也尝试过,live()
但没有成功。我在这里缺少什么吗?