码迷,mamicode.com
首页 > 编程语言 > 详细

javascript prompt示例

时间:2014-09-16 18:50:40      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:style   color   io   os   java   ar   for   cti   on   

<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>

javascript prompt示例

标签:style   color   io   os   java   ar   for   cti   on   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!