JavaScript常用的方法收集

xiaoxiao2024-10-29  15

1.字符串去掉空格

String.prototype.trim  =  function(){        //  用正则表达式将前后空格        //  用空字符串替代。        return  this.replace(/(^\s*)|(\s*$)/g,  "");}

2.得到当前年的最后一天

function getYearEnd(){ var strDate = ""; var myYear,myMonth,myDay;  var curDate = new Date();  myYear = curDate.getYear();  strDate = myYear + "-12-31";  return strDate;}

3

function addDate(d){ var arys= new Array(); arys=d.split('-'); var day =new Number(arys[2])+1; var strday=day+""; if(strday.length==1){  strday="0"+strday } uom = arys[0] + "-" +arys[1] + "-" + strday; return uom;}

转载请注明原文地址: https://www.6miu.com/read-5018739.html

最新回复(0)