【发布时间】:2010-06-24 00:04:03
【问题描述】:
为了让我的问题更具体,我阅读了 .each() for jQuery 的文档,但我有点困惑。我有这个代码:
$.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;
};
现在我不明白的是,为什么每个函数都没有索引或元素?这个 sn-p 代码来自我试图阅读的一个 jQuery 插件。我也不太了解 $.fn。在顶部,我知道它代表原型,但这里到底发生了什么?
【问题讨论】:
标签: javascript jquery jquery-plugins