为了让我的问题更加具体,我阅读了关于.each()的jQuery文档,但我有点困惑。我有这样的代码:在jQuery中,this.each()是如何工作的?
$.fn.imgAreaSelect = function (options) {
options = options || {};
this.each(function() {
if ($(this).data('imgAreaSelect')) {
if (options.remove) {
$(this).data('imgAreaSelect').remove();
$(this).removeData('imgAreaSelect');
}
else
$(this).data('imgAreaSelect').setOptions(options);
}
else if (!options.remove) {
if (options.enable === undefined && options.disable === undefined)
options.enable = true;
$(this).data('imgAreaSelect', new $.imgAreaSelect(this, options));
}
});
if (options.instance)
return $(this).data('imgAreaSelect');
return this;
};
现在我不明白这是为什么每个函数都没有索引或元素?这段代码来自我试图阅读的jQuery插件。我也不太了解$ .fn。在顶部,我知道它代表原型,但是到底发生了什么?
但看看第三行的代码:)'this.each(函数({'这一点。具体来说,是什么'this.each('做?我怀疑它是一样的,因为我们没有看到'this'被封装为一个jQuery对象。 – AjaxLeung 2015-08-25 06:58:03