小编Ric*_*rdo的帖子

什么是最优雅的方式来创建一个jQuery插件?

我想知道这三种方法中最好的方法,也许为什么?

1)

(function($) {
    var methods = {
        init    : function(options) {
            if( this.length ){
                var settings = {
                    something   : 'fast'
                };
                return this.each(function(){
                    if ( options ) {
                        $.extend( settings, options );
                    }

                    var $el         = $(this),

                    /* some variables */
                        $selector1  = $el.find('container'),
                        count       = $selector1.length,
                        $selector2  = $el.find('pictures');

                    /* do something e.g.*/
                    doSomething1();
                    doSomething2();

                    function doSomething1() {
                        $selector1.css('width' , '300px');
                    };

                    function doSomething2() {
                        $selector2.each(function(i) {
                            //do something
                        });
                    };  
                });
            }
        },
        update  : function() …
Run Code Online (Sandbox Code Playgroud)

jquery jquery-plugins

5
推荐指数
1
解决办法
1912
查看次数

标签 统计

jquery ×1

jquery-plugins ×1