【发布时间】:2012-06-28 15:44:47
【问题描述】:
;(function ($, w, d, config, undefined) {
$.fn.pluginName = function ( options, config ) {
var pluginName = this;
var defaults = {
//defaults
};
var settings = $.extend({}, defaults, options);
var methods = {
init : function ( settings, options ) {
//init stuff here
}
}
})
})(jQuery, window, document)
// HTML looks like this
<script>
$('.item').pluginName({ methods : 'init' });
</script>
我是插件开发和一般对象的新手,但我试图在没有游泳的情况下深入学习。 :)
基本上,我想通过调用方法变量中的“init”函数来初始化我的插件。我的插件名称是“pluginName”。
我无法调用“init”fn,因为它位于名为“methods”的变量中。
另外,为了更进一步,我需要收集页面上的所有“项目”类,并在里面设置一个数据变量。在我的 init 函数中,我有以下内容:
return this.each(function(){
var $this = $(this),
data = $this.data('pluginName');
if ( ! data ) {
$(this).data('pluginName', {
target : $this
});
}
}).bind(this);
以上返回“this.each 不是函数”
任何帮助将不胜感激!非常感谢!!
【问题讨论】:
标签: jquery function variables plugins init