Jquery event handlers return values

后端 未结 2 1457
野的像风
野的像风 2020-11-30 07:03

Is there any use to return values from .click() and .change() handlers (like return true or return false)?

相关标签:
2条回答
  • 2020-11-30 07:57

    return false in such a handler results in event.stopPropagation() (only for jQuery event handlers, as Tim Down suggested in the comments) and event.preventDefault() being called automatically by jQuery.

    return true is the same as returning nothing (no action is taken by jQuery).

    0 讨论(0)
  • 2020-11-30 08:02

    return false; will stop the event from bubbling up AND suppress the default action.

    In otherwords, returning false is analogous to these two lines

    event.stopPropagation();
    event.preventDefault();
    

    For events that bubble and are cancelable, at least.

    0 讨论(0)
提交回复
热议问题