关于如何动态地在同一页面实现两个<select>互传

关于如何动态地在同一页面实现两个

 1<select>互传 (s1 &lt;==&gt; s2)   
 2  
 3(jaklin )   
 4  
 5  
 6hello! 先祝大家中秋节快乐!   
 7  
 8我们常常会碰到这样一个问题: 如何将在同一页面上的一个<select>或<listbox>的值传到另一个<select>或<listbox>中 ?这是一个很烦人的问题。可是有时候你偏偏会遇到。 那什么办呢?   
 9  
10下面是我“烟酒”了一个上午, 现贴上来让大家共享。 用的方法是很笨也挺麻烦。不过总是有点成就感的。呵呵!大家看看, 指点指点.....   
11  

@ Language=VBScript

 1<html>
 2<head>
 3<meta content="Microsoft Visual Studio 6.0" name="GENERATOR"/>
 4</head>
 5<script language="vbscript">
 6</script>
 7<body bgcolor="#ffffff">
 8<form action="test01.asp" name="form1" target="_self">
 9<p><textarea id="text01" name="text01"></textarea></p>
10<table>
11<tr>
12<td>
13<select language="javascript" name="select1" size="5">
14<option value="11111">11111</option>
15<option value="22222">22222</option>
16<option value="33333">33333</option>
17</select>
18</td>
19<td>
20<label onclick="do_select()"><font color="#ff00dc"><u>-&gt;&gt; </u></font> </label><br/><br/>
21<label onclick="do_select2()"><font color="#ff00dc"><u>&lt;&lt;\- </u></font> </label>
22</td>   

str="function do_select() {" &amp; vbCrlf &amp; _
"if (document.form1.select1.options.length &gt; 0) {"&amp;vbCrlf&amp;_
"var j=0;"&amp;vbCrlf&amp;_
"for(var i=0;i<document.form1.select1.options.length;i++) "if="" "if(document.form1.select1.options(i).selected)="" "j="j+1;" "}"&vbcrlf="" "}"&vbcrlf&="" &="" (j="" ="" break"="" vbcrlf="" {"&vbcrlf="" {"&vbcrlf&=""> 0) {"&amp;vbCrlf&amp; "document.form1.sel2.options[document.form1.sel2.options.length] = new Option(" &amp; _
"document.form1.select1.options[document.form1.select1.selectedIndex].value," &amp; _
"document.form1.select1.options[document.form1.select1.selectedIndex].value);"&amp; vbCrlf
Response.Write "<td><select id="sel2" name="sel2" size="5">"
Response.Write "</select></td>"
str=str&amp;vbCrlf&amp;"document.form1.select1.options[document.form1.select1.selectedIndex]=null;"&amp;vbCrlf &amp; _
"if (document.form1.select1.options.length &gt; 1) {"&amp;vbCrlf '&amp;_
str=str&amp;vbCrlf &amp; "}" &amp; vbCrlf &amp; "}" &amp; vbCrlf&amp; "}" &amp; vbCrlf&amp; "}" &amp; vbCrlf
Response.Write "<scr"& "ipt="" javascript""="" language="">" &amp; vbCrlf
Response.Write str &amp; vbCrlf &amp; ""&amp; vbCrlf

1  

str=""
str="function do_select2() {" &amp; vbCrlf &amp; _
"if (document.form1.sel2.options.length &gt; 0) {"&amp;vbCrlf&amp;_
"var j=0;"&amp;vbCrlf&amp;_
"for(var i=0;i<document.form1.sel2.options.length;i++) "if="" "if(document.form1.sel2.options(i).selected)="" "j="j+1;" "}"&vbcrlf="" "}"&vbcrlf&="" &="" (j="" ="" break"="" vbcrlf="" {"&vbcrlf="" {"&vbcrlf&=""> 0) {"&amp;vbCrlf&amp;
"document.form1.select1.options[document.form1.select1.options.length] = new Option(" &amp; _
"document.form1.sel2.options[document.form1.sel2.selectedIndex].value," &amp; _
"document.form1.sel2.options[document.form1.sel2.selectedIndex].value);"&amp; vbCrlf
str=str&amp;"document.form1.sel2.options[document.form1.sel2.selectedIndex] =null;" &amp; vbCrlf &amp;"}"&amp; vbCrlf &amp;"}"&amp; vbCrlf &amp;"}"
Response.Write "<scr"& "ipt="" javascript""="" language="">" &amp; vbCrlf
Response.Write str &amp; vbCrlf &amp; ""&amp; vbCrlf

 1  
 2</scr"&></document.form1.sel2.options.length;i++)></scr"&></document.form1.select1.options.length;i++)></tr>
 3</table>
 4</form>
 5</body>
 6</html>   
 7  
 8很笨吧, 哈哈!   
 9若那位大虾有更好的方法, 可别忘了给我寄上一份哦。   
10E_Mail: [email protected]</listbox></select></listbox></select></select>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus