<%
Dim list
Set conn=Server.CreateObject("ADODB.Connection")
DBPath1=server.mappath("../db/db.mdb")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DBPath1
set rs=conn.execute("select a from b")
do while not rs.eof   
   list=list&"<option>"&rs("a")&"</option>"
   rs.movenext
Loop
Rs.Close:Set Rs=Nothing
Response.write "<select id='scs' onchange='mselect()'>"&list&"</select>"
Response.write "<select id='scscms'>"&list&"</select>"
%>
<script type="text/javascript">
var option="";
function mselect(){
    var scs=document.getElementById("scs");
    var scscms=document.getElementById("scscms");
    var n=scs.selectedIndex;
    for(var i =0;i<scscms.options.length; i++){
        if(scs.options[n].text==scscms.options[i].text)
        scscms.options.remove(i);
    }
    if(option!="")scscms.add(option);
    option=new Option(scs.options[n].text,"");
}
mselect();
</script>
上面mselect()只能做到,选择scs时,scsms中删除,当scsms中选择值时,此时再重新选择scs时,选择项中也要删除scsms选择值jsselect

解决方案 »

  1.   

    上面mselect()只能做到,选择scs时,scsms中删除
    如何做到当scsms中选择值时,此时再重新选择scs时,选择项中也要删除scsms选择值 
    也就是互相排斥
      

  2.   

    两个select,相同的option,在select1选择某项后,此时去看select2中选择项中select1已选择项会删除,同理2中选择后,1中也会删除(注:多次来回选择后某些前面删除项会添加回去的)
      

  3.   

    LZ可以参考下面的代码msselect(document.getElementById("scs"), document.getElementById("scscms"));var option = "";
    function mselect(sourceSelect, targetSelect){
        var n=sourceSelect.selectedIndex;
        if(option != "") sourceSelect.options.add(option);
        for(var i =0;i<targetSelect.options.length; i++){
            if(sourceSelect.options[n].text==targetSelect.options[i].text)
                targetSelect.options.remove(i);
        }
        
        option = new Option(sourceSelect.options[n].text,"")
    }
      

  4.   

    修改了下<script type="text/javascript">
    var option = "";
    function mselect(scs, scsms){
        var scs;
    var scsms;
    var sourceSelect=document.getElementById(scs);
    var targetSelect=document.getElementById(scsms);
    var n=sourceSelect.selectedIndex;
        if(option != "") sourceSelect.options.add(option);
        for(var i =0;i<targetSelect.options.length; i++){
            if(sourceSelect.options[n].text==targetSelect.options[i].text)
                targetSelect.options.remove(i);
        }
         
        option = new Option(sourceSelect.options[n].text,"")
    }
    </script>
    ok了,再来研究多个select,感觉要双循环
      

  5.   

    多次来回选择测试,还是有问题,两个select选项里数目不对了
      

  6.   

    多次来回选择测试,还是有问题,两个select选项里数目不对了
    两个select的选项数是不一样的且相差1,因为其中一个下拉列表选择一项后,会移除另一个下拉列表内对应的项。
      

  7.   

    多次来回选择测试,还是有问题,两个select选项里数目不对了
    两个select的选项数是不一样的且相差1,因为其中一个下拉列表选择一项后,会移除另一个下拉列表内对应的项。
    问题是有时相差不止1
      

  8.   

    多次来回选择测试,还是有问题,两个select选项里数目不对了
    两个select的选项数是不一样的且相差1,因为其中一个下拉列表选择一项后,会移除另一个下拉列表内对应的项。
    问题是有时相差不止1
    LZ,代码里需要再加判断var isFind = false;
    for(var i =0;i<targetSelect.options.length; i++){
        if(sourceSelect.options[n].text==targetSelect.options[i].text) {
            targetSelect.options.remove(i);
            isFind = true;
        }
    }
    if (isFind) {
        option = new Option(sourceSelect.options[n].text,"");
    } else {
        option = "";
    }
      

  9.   

    多次来回选择测试,还是有问题,两个select选项里数目不对了
    两个select的选项数是不一样的且相差1,因为其中一个下拉列表选择一项后,会移除另一个下拉列表内对应的项。
    问题是有时相差不止1
    LZ,代码里需要再加判断var isFind = false;
    for(var i =0;i<targetSelect.options.length; i++){
        if(sourceSelect.options[n].text==targetSelect.options[i].text) {
            targetSelect.options.remove(i);
            isFind = true;
        }
    }
    if (isFind) {
        option = new Option(sourceSelect.options[n].text,"");
    } else {
        option = "";
    }

    谢谢conanhhy的解答
    if(option != "") sourceSelect.options.add(option); //if(option != "" || option != "请选择") sourceSelect.options.add(option);改成这里就无效了,报错“类型不匹配”