在 jquery 中引用此变量的差异

Difference in referring this variable in jquery

我对下面代码中的这个变量感到困惑。

jQuery.fn.extend({
   check: function() {
     return this.each(function() {
       this.checked = true;
     });
   },
   uncheck: function() {
      return this.each(function() {
        this.checked = false;
      });
   } 
});

// Use the newly created .check() method
$( "input[type='checkbox']" ).check();

请告诉我哪个 this 指的是哪个对象。

this.each中,this指的是提供的jQuery对象中元素的集合。在您的示例中,它将是 input[type="checkbox"] 元素的 all

this.checked 中,thiseach 循环迭代中的单个 DOMElement。