请教高手如果自定义一个简单表格控件,这个控件有属性,方法,事件 如果所有的操作都通过mygrid这个方法来进行的话只有对mygrid方法的参数进行判断了,不同的参数对应不同的处理 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 判断传入的json串 根据key值设置样式 url通过ajax取值 function添加事件 应该不是很轻易就能做好没错误的 (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);在线等,求大家帮帮忙看看。 谢谢 <script>alert('hello')</script> 抛开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"); 如何根据json的名称得到json的句柄 jquery的TREEVIEW插件节点如何选定和取值? 碰到个奇怪的问题,javascript文件名第二个字母出现大写时,不能调用文件中函数 ***javascript如何操作XML?**** 请教日期问题? 在JS中,如何将判断某个值中是否含有特定的字串? 一个关于JavaScript的超高难度问题,(小女生大派送啊,超急在线等。) 急问,能不能在网页中实现ppt的直接打开,而不是提示保存或打开? 如何改变树型菜单的背景颜色 这个效果怎么做出来? 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");