What's the effect of adding 'return false' to a click event listener?

前端 未结 16 1774
南旧
南旧 2020-11-21 22:59

Many times I\'ve seen links like these in HTML pages:

Click here !
16条回答
  •  情话喂你
    2020-11-21 23:12

    WHAT "return false" IS REALLY DOING?

    return false is actually doing three very separate things when you call it:

    1. event.preventDefault();
    2. event.stopPropagation();
    3. Stops callback execution and returns immediately when called.

    See jquery-events-stop-misusing-return-false for more information.

    For example :

    while clicking this link, return false will cancel the default behaviour of the browser.

    Click here !
    

提交回复
热议问题