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);
},

posted @ 2019-07-24 21:18  JAVA开发老菜鸟  阅读(493)  评论(0编辑  收藏  举报