如果所有的操作都通过mygrid这个方法来进行的话只有对mygrid方法的参数进行判断了,不同的参数对应不同的处理
解决方案 »
- 如何使用window.open打开一个不可见的POP窗口
- 这两种脚本的写法有什么不同
- 如何用js实现下拉菜单的跨frame显示啊?高手帮助
- 打开FTP服务器端的文件。。。。大家请帮忙。。。。这个问题很棘手。。。。在线寻找高手。。。。
- 在JavaScript中怎樣調用指定控件的事件?
- 关于提示框 简单
- 多个div层移动问题
- 这叫什么语法? <ilayer id="main" width=&{scrollerwidth}; height=&{scrollerheight}; bgcolor=&{scrollerbgcolor};>
- 请问一个高手级的小问题
- 如何实现使页面处于最前端
- js导出excel
- 求解释一段代码
(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);
在线等,求大家帮帮忙看看。 谢谢
alert('hello')
</script>
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");