Jquery相关总结

1.(1) 判断checkbox是否选中  -----xxx.is(':checked')

   (2)设置checkbox选中或取消    xxx.prop("checked", true/false); 或者  xxx.attr("checked", true/false);  一个不可以使用另一个

2.计算时间差

function CalcTimeSpan(starttime, endtime) {
  var d1 = new Date(starttime);

  var d2 = new Date(endtime);
  var hour = ((d2 - d1) / 1000 / 60 / 60).toFixed(2);//得到小时数保留两位小数
  return hour;
}

3   jquery 处理mvc自带 json返回时间格式 /Date(12321312314)/的处理

function ChangeDateFormat(cellval) {
var date = new Date(parseInt(cellval.replace("/Date(", "").replace(")/", ""), 10));
var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
return date.getFullYear() + "-" + month + "-" + currentDate;
}

原文地址:https://www.cnblogs.com/zxking/p/8630281.html