js插件扩展

1 类级别 

开发扩展其方法时使用$.extend方法,即jQuery.extend(object); 

$.extend({ 
add:function(a,b){returna+b;} , 
minus:function(a,b){returna-b;} 
}); 


页面中调用:

vari = $.add(3,2); 
varj = $.minus(3,2); 


 

2 对象级别 

开发扩展其方法时使用$.fn.extend方法 ,即jQuery.fn.extend(object); 

$.fn.extend({ 
check:function(){ 
returnthis.each({ 
this.checked=true; 
}); 
}, 
uncheck:function(){ 
returnthis.each({ 
this.checked=false; 
}); 
} 
});


页面中调用: 

$('input[type=checkbox]').check(); 
$('input[type=checkbox]').uncheck();


 

3、扩展

$.xy= { 
add:function(a,b){returna+b;} , 
minus:function(a,b){returna-b;}, 
voidMethod:function(){alert("void"); } 
}; 
vari = $.xy.add(3,2); 
varm = $.xy.minus(3,2); 
$.xy.voidMethod();  





/**
*计算工程的根路径
*/
varPVIS_CHART_PATH = (function() {
var protocol = window.location.protocol;
var host = window.location.host;
var pathname = window.location.pathname;
pathname = pathname.substring(0,pathname.indexOf("/", 1) + 1);
return protocol + "//" + host + pathname;
})();


/**
*基本路径
*/
BasePath: PVIS_CHART_PATH + "/theme/pvis/chart/echarts/",



varperson = {
firstName: "John",
lastName : "Doe",
id : 5566,
fullName : function()
{
return this.firstName + " " + this.lastName;
}
};
document.getElementById("demo").innerHTML= person.fullName();


对于js类型转换

类似parseFloat(x); 可以简写成 +(x)



转自:

<http://blog.csdn.net/u012598110/article/details/49760777

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值