开发者

What's the difference between e.preventDefault(); and return false? [duplicate]

This question already has answers here: event.preventDefault() vs. return false (14 answers) Closed 9 years ago.
$("a.avatar").click(function开发者_如何学Go(e){
      e.preventDefault();
      $("#thumbnails").fadeIn();
    });

and

$("a.avatar").click(function(e){
      $("#thumbnails").fadeIn();
          return false;
    });

Both can achieve the same goal for me.


Returning false from jQuery event handlers is equivalent to calling both, e.preventDefault and e.stopPropagation.

So the difference is that preventDefault will only prevent the default event action to occur, i.e. a page redirect on a link click, a form submission, etc. and return false will also stop the event flow.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜