JS中的简单问题,急急急
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题页</title>
<script type="text/javascript">
function checkDate()
{
if(!document.getElementById||!document.createTextNode)
{return;}
if(!document.getElementById('date'))
{return;}
var checkPattern=new RegExp("\\d{2}/\\d{2}/\\d{4}");
var dateValue=document.getElementById('date').value;
if(dateValue=='')
{
alert('Please enter a date');
return false;
}
else
{
while(!checkPattern.test(dateValue) && dateValue!=null)
{
dateValue=prompt('You date was not in the right format.'+'Please enter it as DD/MM/YYYY.',dateValue);
}
return dateValue=null;
}
}
</script>
</head>
<body>
<form action="prompt().htm" method="get" onsubmit="return checkDate();">
<p>
<label for="date">Please enter it as DD/MM/YYYY:</label><br />
<input type="text" id="date" name="date" />
<input type="submit" value="Check" />
<br />
</body>
</html>
我是js的初学者,这段代码不懂,有人能帮我逐句解释一下吗??谢谢!
------解决方案--------------------
document.getElementById('date'),查找是否有date这个id的对象,如果有就正则验证
RegExp("\\d{2}/\\d{2}/\\d{4}") 格式是DD/MM/YYYY格式,如果日期内容为空,则alert('Please enter a date');
否则,检测日期值是否符合规则