如果所有的操作都通过mygrid这个方法来进行的话只有对mygrid方法的参数进行判断了,不同的参数对应不同的处理

解决方案 »

  1.   

    判断传入的json串 根据key值设置样式 url通过ajax取值 function添加事件 应该不是很轻易就能做好没错误的
      

  2.   


     
      (function ($) {
        $.fn.window=function(param){
               if(typeof param=="string"){
                //如果是字条串 表示是要使用方法 我如何根据param 调用$.fn.window.methods里面指定的方法?
                  
               }else {
                //如果是object ,我如何根据param里面 参数调用  $.fn.window.defaults?
               }
              
      }  //我这里定义所有的方法
      $.fn.window.methods={
          open:function(){
            alert("open");
          },
          close:function(){
            alert("close") ;
          } 
      }
      $.fn.window.defaults={
        width:10,
        height:10,
        href:'',
        onSuccessLoad:true
      }
     })(jQuery);
    在线等,求大家帮帮忙看看。 谢谢
      

  3.   

    <script>
    alert('hello')
    </script>
      

  4.   

    抛开jQuery插件不说,假若要写个MyGrid。function MyGrid(dom,options){
      this.dom = $(dom);
      ... 
    }defaultOptions = {};MyGrid.prototype = {
      constructor: MyGrid,
      close: function(){
        this.dom.xxx;
      },
      open: function(){
        this.dom.xxx;
      }
      ...
    }
    好了,现在适配成jQuery插件$.fn.myGrid = function(method,param){
      if(typeof(method) === 'object') {
        param = arguments[0];
        param = $.extend(param,defaultOptions);
        method = null;  //如过第一个是object,则把方法看作是setup
      }  
      return this.each(function(){
        if(method === null) {
          //初始化
          var grid = new MyGrid(this,option); //new
          $(this).data('GridObject',grid); //把new出来的对象放到这个dom节点关联的data中
        } else {
          var grid = $(this).data('GridObject'); //取出grid对象
          if(grid && grid[method]) {
            grid[method].call(grid,param); //运行grid的method方法
          }
        }
      });
    }
    如果你希望一切挂载到jQuery下,那么$.MyGrid = function(dom,options){
      this.dom = $(dom);
      ... 
    }$.MyGrid.defaultOptions = {};$.MyGrid.prototype = {
      constructor: $.MyGrid,
      close: function(){
        this.dom.xxx;
      },
      open: function(){
        this.dom.xxx;
      },
      setRow: function(row){
      
      }
      ...
    }$.fn.myGrid = function(method,param){
      if(typeof(method) !== 'string') {
        param = arguments[0];
        param = $.extend(param,$.MyGrid.defaultOptions);
        method = null;  //如过第一个是object,则把方法看作是setup
      }  
      return this.each(function(){
        if(method === null) {
          //初始化
          var grid = new $.MyGrid(this,option); //
          $(this).data('GridObject',grid); //把new出来的对象放到这个dom节点关联的data中
        } else {
          var grid = $(this).data('GridObject'); //取出grid对象
          if(grid && grid[method]) {
            grid[method].call(grid,param); //运行grid的method方法
          }
        }
      });
    }///////////////////
    //现在就可以这样用啦
    ///////////////////$("#test").myGrid({}).myGrid("setRow",5).myGrid("close");