//Demo1 event.preventDefault()
$('a').click(function (e) {
// custom handling here
e.preventDefault();
});
//Demo2 return false
$('a').click(function () {
// custom handling here
return false;
};
jQuery中return false相当于同时调用e.preventDefault 和 e.stopPropagation。
$('a').click(function (e) {
// custom handling here
e.preventDefault();
});
//Demo2 return false
$('a').click(function () {
// custom handling here
return false;
};
jQuery中return false相当于同时调用e.preventDefault 和 e.stopPropagation。
本文介绍如何使用jQuery阻止超链接的默认行为,通过两种方法:一是使用event.preventDefault(),二是返回false。这两种方式都能取消链接的点击跳转效果,并且return false还等同于阻止事件冒泡。
363





