jQuery Plugin Namespace

后端 未结 5 1538
温柔的废话
温柔的废话 2020-12-23 18:18

How do I create a jQuery plugin so that I can use namespaces in my plugin ?

$(\"#id1\").amtec.foo1();
$(\"#id1\").amtec.foo2();

None of th

5条回答
  •  佛祖请我去吃肉
    2020-12-23 19:17

    I know it's an old question... But why write all this extra code when you can just replace . with _?

    $.fn.amtec_foo1 = function(){ return this.each(function(){}); }
    $.fn.amtec_foo2 = function(){ return this.each(function(){}); }
    

    Better yet, give your plugin a name that's original & project agnostic.

    $.fn.fooize = function(){ return this.html('Element has been Fooized!'); }
    

提交回复
热议问题