我有这样的 html:
<a href="http://google.com" class="extended-link">
<span class="extended-span" data-comment-href="http://example.com">text</span>
</a>
和CSS:
.extended-link {
display: inline-block;
background: green;
width: 200px;
height: 500px;
text-align: center;
}
.extended-span {
display: inline-block;
background: yellow;
margin: 100px 0 0 0;
}
和 js:
$('.extended-span').click(function(event) {
event.stopPropagation();
window.location.href = $(this).attr('data-comment-href');
});
但我无法捕获 .extended-span
点击,它总是触发外部链接重定向。
是否可以在链接内捕获点击(链接必须是可点击的,span 除外)
最佳答案
尝试 event.preventDefault();
而不是 event.stopPropagation();
关于javascript - jQuery:捕捉链接内的点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33414274/