event.preventDefault() vs. return false

使用jquery方式的话,以下是等效的

return false === event.stopPropagation + event.preventDefault() 

//1. event.preventDefault()
$('a').click(function (e) {
// custom handling here
e.preventDefault();
});
//2. return false
$('a').click(function () {
// custom handling here
return false;
});

非jquery的情况,例如<a href="demo.html" onclick="return false;">

其作用只是阻止默认事件行为,不能停止事件冒泡

https://stackoverflow.com/questions/1357118/event-preventdefault-vs-return-false

posted @ 2018-06-15 16:30  悠哉大斌  阅读(242)  评论(0编辑  收藏  举报