复制代码代码如下所示:









数据输入



在window.onload =函数(){

无功alaydate = document.getelementsbyclassname(日期);

对于(var i = 0;i < alaydate.length;i++)

{

我alaydate { }。onchange =函数(){

无功datevalue = this.value;

datevalue = datevalue.replace( / / g,);

datevalue = datevalue.replace( / / g,);

如果(datevalue.length = = 8){

VaR的温度= datevalue.substring(0,4)+-+ datevalue.substring(4,6)+-+ datevalue.substring(6,8);

datevalue =温度;

console.log(datevalue);

}

如果(checkdt(datevalue)){

this.value = datevalue;

}

其他的

{

警报(日期输入错误);

}

}

}

}



功能checkdt(STR)

{

Var(R = str.match / ^( D { }(1,4)- | /)( D {1,2}) / 2( D {1,2}));

如果(r = NULL)

{

返回false;

}

其他的

{

var =新日期(r { 1 },r { 3 } - 1,r { 4 });

返回(d.getfullyear()()= = R { 1 }(d.getmonth()+ 1)= = R { 3 } d.getdate()= = R { 4 });

}

}















把输入yyyy.mm.dd,YYYY.MM.DD转为YYYYMMDD

checkdt该函数是在夫人发现。

这是一个简单实用的功能,合作伙伴可以直接使用它。