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

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

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

Click here !
16条回答
  •  再見小時候
    2020-11-21 23:14

    using return false in an onclick event stops the browser from processing the rest of the execution stack, which includes following the link in the href attribute.

    In other words, adding return false stops the href from working. In your example, this is exactly what you want.

    In buttons, it's not necessary because onclick is all it will ever execute -- there is no href to process and go to.

提交回复
热议问题