开发者

What are the cases when `return false` does not do the same thing as `e.preventDefault()`? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

JavaScript: event开发者_如何学JAVA.preventDefault() vs return false

What are the cases when return false does not do the same thing as e.preventDefault() ?

(Note I'm not talking about jQuery events.. but JavaScript events in general)

The only situation I can think of is a click event on a hyperlink (if you return false in the handler you will still be redirected to the website)

Note that if its not a click event but a mousedown event on the hyperlink return false works same as e.preventDefault().


I believe that return false is equivalent to e.preventDefault(); and e.stopPropagation(); at the same time. However, I recommend that you use the functions and the return false for future and past browser compatibility:

$("#something").click(function(e){
    alert("Something was clicked");
    e.preventDefault();
    return false;
});

Ad@m

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜