代码如下: function checkInputDate(obj){ var strDate=obj.value; var re =/^(\d{4})-(\d{2})-(\d{2})$/; if(re.test(strDate))//判断日期格式符合YYYY-MM-DD标准 { var dateElement=new Date(RegExp.$1,parseInt(RegExp.$2,10)-1,RegExp.$3); if(!((dateElement.getFullYear()==parseInt(RegExp.$1))&&((dateElement.getMonth()+1)==parseInt(RegExp.$2,10))&&(dateElement.getDate()==parseInt(RegExp.$3))))//判断日期逻辑 { document.getElementById("errorMessage").innerText = "You can only input Date.(YYYY-MM-DD) !"; document.getElementById("error").style.display = ""; obj.value= ' '; } }else{ document.getElementById("errorMessage").innerText = "You can only input Date.(YYYY-MM-DD)!"; document.getElementById("error").style.display = ""; obj.value= ''; } }