摘要:本节只是为了做一个记载,实现一个简单的验证
是否需要预占下来框有是和否两个值,当选择“是”时,资源预占原因输入框必须输入值,否则不能跳转,当选“否”时,不需要验证资源预占原因输入框。
有两个文件a.html和b.html,a.html 即下面的代码,b.html只是为了验证通过时候一个跳转页面,不做任何代码编写
因为a.html用的是相对路径,所以要想程序能正常运行,b.html文件必须和a.html放在同一个目录下。
![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2 <html>
3 <head>
4 <title> New Document </title>
5 <meta name="Generator" content="EditPlus">
6 <meta name="Author" content="">
7 <meta name="Keywords" content="">
8 <meta name="Description" content="">
9 </head>
10 <script type="text/javascript">
11 function verify(){
12 var isNeed=document.getElementById("isNeed").value;
13 if(isNeed==1){
14 var reason=document.getElementById("reason").value;
15 if(reason==""||reason==null){
16 alert("预占资源原因不能为空");
17 }else{
18 window.location.href("b.html");
19 }
20 }else{
21 window.location.href("b.html");
22 }
23 }
24 </script>
25 <body>
26 是否需要预占资源
27 <select id="isNeed">
28 <option value="1">是</option><!--通过getElementById()的方法来取到下拉框的值,所以 必须有个id,name可以不要-->
29 <option value="0" selected>否</option>
30 </select>
31 <input type="text" id="reason"/>
32 <input type="button" value="提交" οnclick="verify()"/>
33 </body>
34 </html>