【发布时间】:2012-07-10 03:49:54
【问题描述】:
我正在尝试使用 jquery-boilerplate-v3.1 开发插件,但在“this”和“$(this)”之间感到困惑
in the plugin
...
$.fn[pluginName] = function ( options ) {
//alert($(this).toSource());
return this.each(function () {
if (!$.data(this, 'plugin_' + pluginName)) {
$.data(this, 'plugin_' + pluginName, new Plugin( this, options ));
}
});
};
似乎new Plugin(this, options) 没有返回 Plugin.prototype 上下文中的元素。
相反,我已将其修改为 Plugin($(this), options)。
eg.
$(function(){
$('#container').myPlugin();
});
不使用 $(this) 作为参数,我无法访问插件中的 this.element,.toSource() 返回空对象({})。
通过修改为 $(this) 或如何使用 this 参数访问#container,我的方法是否正确。
TIA。
【问题讨论】:
-
似乎这个世界上有很多“样板”。我上面说的是从[link]jqueryboilerplate.com下载的盘子
标签: jquery boilerplate