通过下拉框的值来确定输入框是否可以为空的代码


有两个文件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>

« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3