我有一个双重事件要管理。这两个事件都是“点击”,它们是用 jquery 处理的。 html 如下:
<div class="siteMap" style="width:23%;">
<h5>Divisione Anticontraffazione</h5>
<span class="menufooter">
<span class="link1"><a href="#scheda1">Introduzione</a></span><br>
<span class="link2"><a href="#scheda2">Filosofia</a></span><br>
<span class="link3"><a href="#scheda3">Negozio online</a></span></span><br>
</div>
然后我有我的点击事件,它在菜单页脚跨度内和每个链接跨度内触发。代码是这样的:
$(document).ready(function() {
$('span.menufooter').click(function() {
//my code here
});
$("span.link1").click(function() {
//my code here
});
});
我需要一个事件捕获操作,点击 span menufooter 必须在点击 span link1 触发之前触发事件。此时,这两个事件都没有触发。有什么提示吗?
最佳答案
如何只在 .menufooter
上触发事件
$(document).ready(function() {
$('span.menufooter').click(function(e) {
//my code here 1
// Capture Event Propagation
if ( $("span .link1").find(e.target).length>0 ){
//my code here 2
};
});
});
关于javascript - 使用 jquery 捕获事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20706198/