【发布时间】:2011-10-13 08:38:17
【问题描述】:
当您单击 div 中的链接时,我会尝试阻止 jq click()。
HTML
<div id="all">
<div id="test">
<a href="http://google.de">google</a>
</div>
</div>
JS
$('#test').click(function() { alert('only when i click the div'); });
$('a').click(function(e) {
e.stopPropagation();
e.preventDefault();
$('body').append(e.target.href);
});
这段代码很好用,但我的内容是动态的,所以我需要一个delegate() 解决方案。
下面的代码不起作用。但为什么?有什么问题?
$('#all').delegate("a", "click", function(e)
{
e.stopPropagation();
e.preventDefault();
$('body').append(e.target.href);
});
【问题讨论】:
-
“不工作”对问题的描述不是很准确...