In JQuery when should you use .bind() over .click() - or any other given event?

后端 未结 5 1441
离开以前
离开以前 2021-02-08 03:22

I understand the difference between Live and Bind but when should I use use .bind() over a \'standard\' event method as shown below.

Are there any key differ

相关标签:
5条回答
  • 2021-02-08 03:52

    They're effectively the same. However, using bind() allows you to make use of namespaced events. This is especially useful when writing plugins.

    0 讨论(0)
  • 2021-02-08 03:52

    They are the same. See here

    0 讨论(0)
  • 2021-02-08 03:57

    in "bind" you can use multiple events

    $('#foo').bind('mouseenter mouseleave', function() {
      $(this).toggleClass('entered');
    });
    
    0 讨论(0)
  • 2021-02-08 04:04

    I use the explicit methods when available. I use the bind when a method isn't available like for window.onbeforeunload

    The other time to use bind is if your are developing and switching between "live" and "bind".

    0 讨论(0)
  • 2021-02-08 04:15

    use .bind when you want to bind to "event.namespace"

    Actaully almost always use .bind and almost always use namespaces.

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