jquery 常用工具方法
//计算年龄
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);
},
本文来自博客园,作者:JAVA开发老菜鸟,转载请注明原文链接:https://www.cnblogs.com/sam-uncle/p/11240905.html