验证是否为空

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5 <title>验证是否为空</title>
 6 <script type="text/javascript">
 7     function checkForm(yourinfo){
 8         if(yourinfo.namestring.value==""||yourinfo.namestring.value==null){
 9             alert("请输入你的名字");
10             return(false);
11         }
12         else{
13             return(true);
14         }
15     }
16 </script>
17 </head>
18 
19 <body>
20 <form name="info" method="post" onSubmit="return checkForm(this);">
21     <p>姓名:<input type="text" name="namestring" size="60"/></p>
22     <p><input type="submit" value="提交" /> <input type="reset" value="重置" /></p>
23 </form>
24 </body>
25 </html>
posted @ 2012-08-16 16:20  yexingwen  阅读(298)  评论(0编辑  收藏  举报