常用函数及方法集

1、获取 url 地址的参数

function GetQueryString(name) {

  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");

       var r = window.location.search.substr(1).match(reg);

        if (r != null) {

              return decodeURI(r[2]);

         } else {

               return null;

          }

}

2、checkbox 最多只能选几项  

    if (this.checked && elem.filter(':checked').length > maxLength) this.checked = false

3、时间日期格式转化 

function isZero(m){
  return m<10?'0'+m:m
}
function formatNewDate(timeSrt,type=true) {
  var timeReg = timeSrt.replace(/./g, '/')
  //timeReg = timeSrt.replace(/-/g, '/')
  var time = new Date(timeReg);
  var y = time.getFullYear();
  var m = time.getMonth()+1;
  var d = time.getDate();
  var h = time.getHours();
  var mm = time.getMinutes();
  var s = time.getSeconds();
  //return y+'/'+isZero(m)+'/'+isZero(d)+' '+isZero(h)+':'+isZero(mm)+':'+isZero(s);
  if(type){
    return isZero(m)+'/'+ isZero(d)+' '+isZero(h)+':'+isZero(mm)
  }else{
    return isZero(m)+'月'+ isZero(d)+'日'
  }
}
原文地址:https://www.cnblogs.com/xqmyhome/p/11956982.html