JavaScript表单验证

 1 document.getElementById("myPoint").innerHTML="显示时间";
 2 
 3 function displayDate(var1, var2) {
 4     document.getElementById("demo").innerHTML=Date()
 5     // alert("Welcome" + var1 + var2)
 6 }
 7 
 8 var x=3
 9 var y=5
10 var z = x + y
11 document.write(x + "<br>")
12 document.write(y + "<br>")
13 document.write(z + "<br>")
14 
15 function validateForm() {
16     var v = document.forms['myForm']['input_name'].value;
17     if (v==null || v==''){
18         alert("输入不能为空");
19         return false;
20     }
21 }
 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8" content="This is a meta data" name="dengyexun">
 5     <title>Title</title>
 6     <link rel="stylesheet" type="text/css" href="home.html">
 7     <style>
 8 
 9     </style>
10 
11 </head>
12 <body>
13     <p id="myPoint">content</p>
14     <h1>The first JavaScript sample</h1>
15     <p id="demo">采用外部js文件</p>
16     <button type="button" onclick="displayDate('deng', 'yexun')">please click!</button>
17     <br>
18     <hr>
19     <form name="myForm" action="/show/" onsubmit="return validateForm()" method="post">
20         {% csrf_token %}
21         姓名:<input name="input_name" type="text"><br>
22         <input type="submit" value="提交">
23     </form>
24 
25 
26     <script src="/static/js/myScript.js">
27     </script>
28 </body>
29 </html>

 

posted @ 2017-11-27 17:10  今夜无风  阅读(194)  评论(0编辑  收藏  举报