有两个文件a.html和b.html,a.html 即下面的代码,b.html只是为了验证通过时候一个跳转页面,不做任何代码编写 因为a.html用的是相对路径,所以要想程序能正常运行,b.html文件必须和a.html放在同一个目录下。 复制代码 代码如下: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title> New Document </title> <meta name="Generator" content="EditPlus"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> </head> <script type="text/javascript"> function verify(){ var isNeed=document.getElementById("isNeed").value; if(isNeed==1){ var reason=document.getElementById("reason").value; if(reason==""||reason==null){ alert("预占资源原因不能为空"); }else{ window.location.href("a.html"); } }else{ window.location.href("b.html"); } } </script> <body> 是否需要预占资源 <select id="isNeed"> <option value="1">是</option><!--通过getElementById()的方法来取到下拉框的值,所以 必须有个id,name可以不要--> <option value="0" selected>否</option> </select> <input type="text" id="reason"/> <input type="button" value="提交" onclick="verify()"/> </body> </html>
推荐阅读
多浏览器兼容性比较好的复制到剪贴板的js代码
对于非ie浏览器他是用flash来实现的,js代码如下: 复制代码 代码如下: <script type="text/javascript"> function copy_code(copyText) { if (window.clipboardData) { window.clipboardData.setData("Text", cop>>>详细阅读
本文标题:通过下拉框的值来确定输入框是否可以为空的代码
地址:http://www.17bianji.com/kaifa2/JS/24058.html
1/2 1