左边select内容选择到右边select内容里面的js实现方法(可以多选和全选)
<html><head></head><BODY><script language="JavaScript">function copyToList(from,to) //from表示:包含可选择项目的select对象名字 to表示:列出可选择项目的select对象名字//你可以根据你的具体情况修改{fromList = eval('document.forms.' + from);toList = eval('document.forms.' + to);if (toList.options.length > 0 && toList.options.value == 'temp'){ toList.options.length = 0;}var sel = false;for (i=0;i<fromList.options.length;i++){ var current = fromList.options; if (current.selected){ sel = true; if (current.value == 'temp'){ alert ('你不能选择这个项目!'); return; } txt = current.text; val = current.value; toList.options = new Option(txt,val); fromList.options = null; i--; }}}//这是当用户按下提交按钮时,对列出选择的select对象执行全选工作,让递交至的后台程序//能取得相关数据function allSelect(){List = document.forms.chosen;if (List.length && List.options.value == 'temp') return;for (i=0;i<List.length;i++){ List.options.selected = true;}}function copyAll(from,to){var fromList = eval('document.forms.' + from);var toList = eval('document.forms.' + to);if (toList.options.length > 0 && toList.options.value == 'temp'){ toList.options.length = 0;}for (i=0;i<fromList.options.length;i++){ var current = fromList.options; toList.options = new Option(current.text,current.value); fromList.options = null; i--;}}</script><table border="0"> <form >
<tr>
<td>
<select name="possible" size="4" MULTIPLE width=200 style="width: 200px">
<option value="1">中国广州
<option value="2">中国上海
<option value="3">中国北京
<option value="4">中国武汉
</select>
</td>
<td><a href="javascript:copyToList('possible','chosen')"></a>
<br>
<br>
<a href="javascript:copyAll('possible','chosen')"></a>
<br><br>
</a><a href="javascript:copyToList('chosen','possible')">/a> <br><br>
<a href="javascript:copyAll('chosen','possible')"></a>
<br>
</td>
<td>
<select name="chosen" size="4" MULTIPLE width=200 style="width: 200px;">
<option value="temp">从左边选择你的地区
</select>
</td>
</tr>
</form>
</table>
</BODY>
</html>
页:
[1]