解决方案 »

  1.   

    function fn(){
    var i=0;
    var arg = arguments;
    this.style.backgroundColor = 'red';
    this.innerText = 'can change ' + (++i) + 'arg1:' + arg[0] + 'arg2' + arg[1];
    }

    $.fn.myMethod = function(fn,arg1,arg2){
    var args = [].slice.call(arguments,1);
    this.each(fn,args);
    return this;
    }
    $("div").myMethod(fn,'aa','bb');
      

  2.   

    明确一下,应该这样写
    function fn(v1,v2){
    var that = this;  

    }

    $.fn.myMethod = function(fn,v1,v2){
    return  this.each(function(k,v){
    //fn(v1,v2)   //this is window;
    $.proxy(fn,this)(v1,v2);  //this is the element
    })
    }

    $("div").myMethod(fn);
      

  3.   

    http://www.iteye.com/topic/545971
    这个很不错 基本是把英文教程翻译过来了 对插件的教学挺全了
      

  4.   


     (function ($) {
                $.extend($.fn, {           
                    myMethod: function (fn, args) {                  
                        //this是全部select 回来的jquery对象集合
                        //用.each loop
                        this.each(function (index, value) {
                            //这里可以写逻辑了                       
                            var value = this.value;  //这里的this是dom 
                            fn(value, this); //调用传进来的方法                      
                        });
                        return this;//把jquery对象集合在返回出去,这样可以连续引用 
                    }
                });
            })(jQuery);    
            $(function () {
                $("#inputtext").myMethod(function (value, elem) {
                    alert(value);
                }, "args").remove();
            });