怎样动态的从一个select框将数据移到另一个select框?

左边是未加入用户列表,右边是已加入用户列表,如何用javascript实现点一个按钮将左边所选的移到右边?

 1<html>
 2<head>
 3<title> emu </title>
 4<script language="JavaScript">   
 5<!--   
 6function exchange(v){   
 7elm1=document.getElementsByName("s1")[v];   
 8elm2=document.getElementsByName("s1")[1-v];   
 9for (var i=elm1.length-1;i>-1;i--){   
10op=elm1.options[i];   
11if (op.selected){   
12elm2.options[elm2.length]=new Option(op.text,op.value);   
13elm1.options[i]=null;   
14}   
15}   
16}   
17//-->   
18</script>
19</head>
20<body>
21<select multiple="" name="s1" size="10" style="width:100">
22<option>test0</option>
23<option>test1</option>
24<option>test2</option>
25<option>test3</option>
26<option>test4</option>
27<option>test5</option>
28<option>test6</option>
29<option>test7</option>
30<option>test8</option>
31<option>test9</option>
32</select>
33<select multiple="" name="s1" size="10" style="width:100"></select>
34<br/>         
35<input onclick="exchange(0)" type="button" value="&gt;&gt;"/>             
36<input onclick="exchange(1)" type="button" value="&lt;&lt;"/>
37</body>
38</html>
Published At
Categories with Web编程
comments powered by Disqus