当我想阻止我正在使用的 anchor 标记的默认行为时
<a href="javascript:void(0);">link</a>
哪个是最有效的解决方案?
最佳答案
优雅降级解决方案的示例:
<a href="no-script.html" id="myLink">link</a>
<script>
document.getElementById("myLink").onclick = function() {
// do things, and then
return false;
};
</script>
关于javascript - 防止 anchor 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4387580/