阻止事件冒泡
- return false;
- event.stopPropagation();
两种方式都可阻止事件冒泡
$(".son").click(function (event) {
alert("son");
// return false;
event.stopPropagation();
});
$(".father").click(function () {
alert("father");
});
阻止默认行为
- return false;
- event.preventDefault();
- 两种方式都可阻止默认行为
$("a").click(function (event) {
alert("弹出注册框");
// return false;
event.preventDefault();
});

博客介绍了jQuery中阻止事件冒泡和默认行为的方法。阻止事件冒泡可使用return false和event.stopPropagation();阻止默认行为可使用return false和event.preventDefault()。
752

被折叠的 条评论
为什么被折叠?



