87,907
社区成员
发帖
与我相关
我的任务
分享
<%
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>
<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,感觉要双循环
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,"")
}
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 = "";
}
[/quote]
谢谢conanhhy的解答
if(option != "") sourceSelect.options.add(option); //if(option != "" || option != "请选择") sourceSelect.options.add(option);改成这里就无效了,报错“类型不匹配”
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 = "";
}