我希望的是让option1选A值时候,option2下拉菜单就不能选B值,用AND将这两句连起来没有效果,麻烦达人指点一下,谢谢先~
if(document.form.option1.value=='A' AND document.form.option2.value=='B'){
alert("请检查option1和option2的选项!");
document.form.option2.focus();
return false;
}
}
if(document.form.option1.value=='A' AND document.form.option2.value=='B'){
alert("请检查option1和option2的选项!");
document.form.option2.focus();
return false;
}
}
==>
document.form.option1.value=='A' && document.form.option2.value=='B'
同时(IE6)页面左下角显示!感叹号说有错
var osel = document.getElementById('selectId');
var osel2 = document.getElementById('select2Id');
var oindex = osel.options[osel.selectedIndex].value;
var oindex2 = osel2.options[osel2.selectedIndex].value;
if(oindex == 'A' && oindex2 == 'B')
alert("请检查option1和option2的选项!");
document.getElementById("option2").focus();
return false;
}
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head><body>
<script LANGUAGE="javascript">
if(document.getElementById("option1").value=='A' && document.getElementById("option2").value=='B'){
alert("请检查option1和option2的选项!");
document.getElementById("option2").focus();
return false;
}
</script> <form action="e.php" method="POST" name="form"> <select name="option1">
<option>A</option>
<option>C</option>
</select>
<select name="option2">
<option>B</option>
<option>D</option>
</select>
<input type="submit" name="submit" value="submit"></input>
</form></body>
</html>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head><body>
<script LANGUAGE="javascript">
function check(selfObj){
var a = document.getElementById('option1') ;
var b = document.getElementById('option2') ;
if(a.options[a.selectedIndex].text=='A' && b.options[b.selectedIndex].text=='B'){
alert("请检查option1和option2的选项!");
selfObj.selectedIndex = 0 ;
}
}
</script> <form action="e.php" method="POST" name="form"> <select id="option1" name="option1" onchange="check(this)">
<option>-=请选择=-</option>
<option>A</option>
<option>C</option>
</select>
<select id="option2" name="option2" onchange="check(this)">
<option>-=请选择=-</option>
<option>B</option>
<option>D</option>
</select>
<input type="submit" name="submit" value="submit"></input>
</form></body>
</html>