我对下面代码中的这个变量感到困惑。
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"]
元素。
在 this.checked
中,this
是 each
循环迭代中的单个 DOMElement。
关于javascript - 在 jquery 中引用这个变量的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30759521/