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

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

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

Click here !
16条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-21 23:32

    By default, when you click on the button, the form would be sent to server no matter what value you have input.

    However, this behavior is not quite appropriate for most cases because we may want to do some checking before sending it to server.

    So, when the listener received "false", the submitting would be cancelled. Basically, it is for the purpose to do some checking on front end.

提交回复
热议问题