我刚刚开始编写jQuery插件.我写了三个小插件,但我只是简单地将行复制到我的所有插件中而实际上并不知道它意味着什么.有人能告诉我更多关于这些的事吗?也许有一天解释会在编写框架时派上用场:)
这是做什么的?(我知道它以某种方式扩展了jQuery,但还有其他有趣的事情要知道)
(function($) {
})(jQuery);
Run Code Online (Sandbox Code Playgroud)
以下两种编写插件的方法有什么区别:
类型1:
(function($) {
$.fn.jPluginName = {
},
$.fn.jPluginName.defaults = {
}
})(jQuery);
Run Code Online (Sandbox Code Playgroud)
类型2:
(function($) {
$.jPluginName = {
}
})(jQuery);
Run Code Online (Sandbox Code Playgroud)
类型3:
(function($){
//Attach this new method to jQuery
$.fn.extend({
var defaults = {
}
var options = $.extend(defaults, options);
//This is where you write your plugin's name
pluginname: function() {
//Iterate over the current set of matched elements
return this.each(function() {
//code to be inserted here
});
}
});
})(jQuery);
Run Code Online (Sandbox Code Playgroud)
我可能会离开这里,也许意味着同样的事情.我很迷惑.在某些情况下,这似乎不适用于我使用Type 1编写的插件.到目前为止,Type …