jquery 常用工具方法

2022-10-18,,

//计算年龄
calcage : function(birthday, calcdate){
var num = (calcdate.getmonth()<birthday.getmonth() || calcdate.getmonth()==birthday.getmonth() && calcdate.getdate()<birthday.getdate())?1:0;
return calcdate.getfullyear()-birthday.getfullyear() - num;
},
//字符串转日期
string2date : function(date){
var sd = date.split('-');
return new date(sd[0],sd[1] - 1,sd[2]);
},
//日期转字符串
date2string : function(data) {
if (!data) {
return "";
}
var date = new date(data);
var year = date.getfullyear();
var month = date.getmonth() + 1;
var day = date.getdate();
month = month >= 10 ? month : "0" + month;
day = day >= 10 ? day : "0" + day;
return year + "-" + month + "-" + day;
},
//点全选checkbox
checkall : function (){
var checked = $("#checkallbox").prop("checked");
$('input[name="subcheckbox"]').prop('checked',checked);
},
//若有项目取消勾选,全选取消,否则全选勾选
ifcheckall : function (){
var roles = $('input[name="subcheckbox"]');
for(var i = 0 ; i < roles.length ; i++){
if(!roles[i].checked){
$("#checkallbox").prop("checked",false);
return;
}
}
$("#checkallbox").prop("checked",true);
},

《jquery 常用工具方法.doc》

下载本文的Word格式文档,以方便收藏与打印。