What's the difference between '$(this)' and 'this'?

前端 未结 7 1581
面向向阳花
面向向阳花 2020-11-21 07:18

I am currently working through this tutorial: Getting Started with jQuery

For the two examples below:

$(\"#orderedlist\").find(\"li\").each(function          


        
相关标签:
7条回答
  • 2020-11-21 08:05

    When using jQuery, it is advised to use $(this) usually. But if you know (you should learn and know) the difference, sometimes it is more convenient and quicker to use just this. For instance:

    $(".myCheckboxes").change(function(){ 
        if(this.checked) 
           alert("checked"); 
    });
    

    is easier and purer than

    $(".myCheckboxes").change(function(){ 
          if($(this).is(":checked")) 
             alert("checked"); 
    });
    
    0 讨论(0)
提交回复
热议问题