如何使用 jQuery 启用或禁用 anchor ?
最佳答案
为了防止 anchor 跟随指定的 href
,我建议使用 preventDefault()
:
// jQuery 1.7+
$(function () {
$('a.something').on("click", function (e) {
e.preventDefault();
});
});
// jQuery < 1.7
$(function () {
$('a.something').click(function (e) {
e.preventDefault();
});
// or
$('a.something').bind("click", function (e) {
e.preventDefault();
});
});
参见:
http://docs.jquery.com/Events/jQuery.Event#event.preventDefault.28.29
另请参阅之前关于 SO 的问题:
关于jquery - 如何使用 jQuery 启用或禁用 anchor ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1164635/