javascript prompt示例

<html lang="en">
<head>
  <title>Date example</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('Your date was not in the right format.'
+'Please enter it as DD/MM/YYYY.',dateValue);
}
return dateValue!=null;
}
}
</script>
</head>
<body>
  <h1>Events search</h1>
  <form action="eventssearch.php" method="post" onsubmit="return checkDate();">
   <p>
    <label for="date">Date in the format DD/MM/YYYY:</label><br/>
    <input type="text" id="date" name="date"/>
    <input type="submit" value="Check"/>
   <br/>(example 23/01/1933)
   </p>
  </form>
</body>
</html>

原文地址:https://www.cnblogs.com/vonk/p/3975412.html