Difference between .bind and other events

后端 未结 3 713
刺人心
刺人心 2021-02-14 02:09

What is the difference between the following lines of code, or are they just 2 different ways to write the same thing:

$(\"p\").click(function() { some code here         


        
相关标签:
3条回答
  • 2021-02-14 02:48

    The first version is just a shorthand for the second one.

    0 讨论(0)
  • 2021-02-14 03:00

    Also note that binds allows for custom events

    $(elem).bind('myEvent', function(){
       alert('myEvent!');
    });
    $(elem).trigger('myEvent'); //alerts 'myEvent!'
    
    0 讨论(0)
  • 2021-02-14 03:06

    It also allows you to bind the same anonymous method to multiple events like:

    $("p").bind("click dblclick mouseover mouseout", function(){ some other code here });
    
    0 讨论(0)
提交回复
热议问题