日期:2014-05-16  浏览次数:20387 次

另开一贴,原在asp,关于两个select互排
<%
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选择值
js select

------解决方案--------------------
引用:
Quote: 引用:

Quote: 引用:

Quote: 引用:

修改了下
<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,感觉要双循环

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

两个select的选项数是不一样的且相差1,因为其中一个下拉列表选择一项后,会移除另一个下拉列表内对应的项。

问题是有时相差不止1

LZ,代码里需要再加判断

var isFind = false;
for(var i =0;i<targetSelect.options.length; i++){