我有一个链接元素(实际上是某个类的所有链接),我已将单击事件绑定(bind)到该元素。
这是一个示例链接元素:
<a id="2" class="paginationclick" style="cursor: pointer;" href="">2</a>
这是绑定(bind):
$(".paginationclick").click(function(e) {
displayAccountSearchResults(e);
if (e.stopPropagation) {
e.stopPropagation();
} else {
e.cancelBubble = true;
}
});
displayAccountSearchResults(e) 执行正常,但页面会重新加载。我不想重新加载页面。为什么 stopPropagation/cancelBubble 不起作用?
最佳答案
您需要一个e.preventDefault
$(".paginationclick").click(function(e) {
e.preventDefault()
displayAccountSearchResults(e);
if (e.stopPropagation) {
e.stopPropagation();
} else {
e.cancelBubble = true;
}
});
关于Javascript - 无法阻止链接加载页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16531524/