gpt4 book ai didi

jQuery 插件命名空间

转载 作者:行者123 更新时间:2023-12-03 21:35:57 25 4
gpt4 key购买 nike

如何创建 jQuery 插件以便可以在插件中使用命名空间?

$("#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 插件命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1537848/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com