我要实现如下效果:
<html>
<head>
<title>测试</title>
<form method="post" action="1.jsp" name="form1" >
<table width="50%" border="2" align="center" >
<tr>
<td align="left"><font size="2" color="#000000">条件</font></td>
<td align="left"><select name="a" onChange="t()">
<option selected ></option>
<option value1="0">可以选择</option>
<option value1="1">不能选择</option>
</select>
<td align="left"><font size="2" color="#000000">学历</font>
<td align="left"><select name="b" >
<option selected ></option>
<option >本科</option>
<option >大专</option>
</select>
</tr>
</table>
<p align="center">
<input type="submit" name="submit" value="提交">
</p>
</form>
</body>
<script language=javascript>
function t()
{
var tmp = document.all.a.options[document.all.a.selectedIndex].value1;
if(tmp == 1 )
{
document.all.b.disabled= true;
document.all.b.style.background="#C0C0C0";
}
else
{
document.all.b.disabled= false;
document.all.b.style.background="#FFFFFF";
}
}
</script>
</html>
但由于我用disabled了,所以不能正确把数据提交到1.jsp里了。我要的效果就是在条件里选择了“可以选择”那么就在学历里可以选择,反之学历就不能选。
------解决方案--------------------
<html>
<head>
<title>测试</title>
<form method="post" action="1.jsp" name="form1" >
<table width="50%" border="2" align="center" >
<tr>
<td align="left"><font size="2" color="#000000">条件</font></td>
<td align="left">
<select id="a" name="a">
<option selected ></option>
<option value="1">可以选择</option>
<option value="2">不能选择</option>
</select>
<td align="left"><font size="2" color="#000000">学历</font>
<td align="left">
<select name="b" onchange="check(this)">
<option selected ></option>
<option >本科</option>
<option >大专</option>
</select>
</tr>
</table>
<p align="center">
<input type="submit" name="submit" value="提交">
</p>
</form>
</body>
<script language=javascript>
function check(sel){
if(document.getElementById("a").value != "1"){
sel.childNodes[1].selected = true;
}
}
</script>
</html>
------解决方案--------------------
可以设置为disable,因为设置为disable后表单提交时会被忽略掉,所以要在onsubmit方法中removeAttribute("disable")
------解决方案--------------------