<%
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
------解决方案--------------------
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 = "";
}