jQuery插件命名空间 [英] jQuery Plugin Namespace
本文介绍了jQuery插件命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何创建jQuery插件,以便可以在插件中使用命名空间?
How do I create a jQuery plugin so that I can use namespaces in my plugin ?
$("#id1").amtec.foo1();
$("#id1").amtec.foo2();
这些似乎都不起作用.
(function($) {
var amtec = {
$.fn.foo1 : function(){ return this.each(function(){}); },
$.fn.foo2 : function(){ return this.each(function(){}); }
};
})(jQuery);
(function($) {
$.fn.amtec = function(){
var foo1 = function(){ return this.each(function(){}); };
var foo2 = function(){ return this.each(function(){}); };
}
})(jQuery);
推荐答案
(function($) {
$.fn.amtec = function () {
var jq = this;
return {
foo1: function(){
return jq.each(function(){});
},
foo2: function(){
return jq.each(function(){});
}
}
};
})(jQuery);
这篇关于jQuery插件命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文