简单连动,只显示部分option
<select name= "s1 " onChange= "type_change(this.options[this.selectedIndex].value); ">
<option value= "1 ">
<option value= "2 ">
<option value= "3 ">
</select>
<select name= "s2 ">
<option value= "1 ">
<option value= "2 ">
<option value= "3 ">
</select>
我想选S1中1 S2全显示1,2,3
选s1中的2 s2 只显示 2,3
如何实现??
------解决方案-------------------- <select name= "s1 " onChange= "type_change(this.options[this.selectedIndex].value); ">
<option value= "1 "> 1 </option>
<option value= "2 "> 2 </option>
<option value= "3 "> 3 </option>
</select>
<select name= "s2 ">
<option value= "1 "> 1 </option>
<option value= "2 "> 2 </option>
<option value= "3 "> 3 </option>
</select>
<script language=javascript>
function type_change(index)
{
var obj=document.getElementById( "s2 ")
if(index== '2 ')
{
obj.options[1]=null
}
else
{
obj.options[1]=new Option( "2 ", "2 ")
obj.options[2]=new Option( "3 ", "3 ")
}
}
</script>
------解决方案-------------------- <select name= "s1 " onChange= "type_change(this.options[this.selectedIndex].value); ">
<option value= "1 "> 1 </option>
<option value= "2 "> 2 </option>
<option value= "3 "> 3 </option>
</select>
<select name= "s2 ">
<option value= "1 "> 1 </option>
<option value= "2 "> 2 </option>
<option value= "3 "> 3 </option>
</select>
<script language=javascript>
function type_change(index)
{
var obj=document.getElementById( "s2 ")
if(index== '2 ')
{
obj.options[0]=null
obj.selectedIndex = 0;
}
else
{
obj.options[0]=new Option( "1 ", "1 ")
obj.options[1]=new Option( "2 ", "2 ")
obj.options[2]=new Option( "3 ", "3 ")
}
}
</script>