当前位置: 代码迷 >> JavaScript >> 新手一个下拉选择菜单的有关问题,多谢你们了
  详细解决方案

新手一个下拉选择菜单的有关问题,多谢你们了

热度:112   发布时间:2012-02-29 16:44:11.0
新手请教大家一个下拉选择菜单的问题,谢谢你们了
做三个选择下拉菜单,里面都有1,2,3个选项目,在第一个下拉菜单里选择了选项1,则后两个菜单里就没有选项1了,就是这个道理,在其中任意一个选了一个项目,则这个选项就不出现在其他两个下拉菜单中,用html+javascript实现,请大家帮帮我,谢谢了

------解决方案--------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME= "Generator " CONTENT= "EditPlus ">
<META NAME= "Author " CONTENT= " ">
<META NAME= "Keywords " CONTENT= " ">
<META NAME= "Description " CONTENT= " ">
<SCRIPT LANGUAGE= "JavaScript ">
<!--
function removeOption(){
var objSel1 = document.getElementById( "sel1 ");
var sValue = objSel1.options[objSel1.selectedIndex].text;

for(var i=0; i <document.getElementById( "sel2 ").options.length;i++){
if(document.getElementById( "sel2 ").options[i].text == sValue){
document.getElementById( "sel2 ").remove(i);
}
}

for(var i=0; i <document.getElementById( "sel3 ").options.length;i++){
if(document.getElementById( "sel3 ").options[i].text == sValue){
document.getElementById( "sel3 ").remove(i);
}
}

}
//-->
</SCRIPT>
</HEAD>

<BODY>
<FORM METHOD=POST ACTION= " ">

<SELECT NAME= " " id= "sel1 " onchange= "removeOption() ">
<option value= "1 "> 1 </option>
<option value= "2 "> 2 </option>
<option value= "3 "> 3 </option>
</SELECT>
<SELECT NAME= " " id= "sel2 ">
<option value= "1 "> 1 </option>
<option value= "2 "> 2 </option>
<option value= "3 "> 3 </option>
</SELECT>
<SELECT NAME= " " id= "sel3 ">
<option value= "1 "> 1 </option>
<option value= "2 "> 2 </option>
<option value= "3 "> 3 </option>
</SELECT>

</FORM>
</BODY>
</HTML>
  相关解决方案