日期:2014-05-16  浏览次数:20391 次

求js操作listbox
两个listbox可以相互移动(多项,删除)

------解决方案--------------------
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> made by meixx </title>
<script language= "javascript ">
<!--
function Add(ObjSource,ObjTarget){
for(var i=ObjSource.length-1;i> =0;i--){
if(ObjSource.options[i].selected){
ObjTarget.add(new Option(ObjSource.options[i].text,ObjSource.options[i].value,true));
ObjSource.options.removeChild(ObjSource.options[i]);
}
}
}
function AddAll(ObjSource,ObjTarget){
SelectAll(ObjSource);
Add(ObjSource,ObjTarget);
}
function SelectAll(ObjSource){
for(var i=0;i <ObjSource.length;i++){
ObjSource.options[i].selected=true;
}
}

function doSubmit(){
SelectAll(frmDisplay.dltTarget);
//frmDisplay.action= " ";//设置form 提交的action
alert(frmDisplay.action);
//frmDisplay.submit();//取消注释即可,提交上去的options
}
//->
</script>
</head>

<body>
<table width= "350 " border= "1 " style= "border-collapse:collapse " bordercolor= "#111111 " cellpadding= "0 " cellspacing= "0 ">
<tr>
<td width= "150 ">
<select name= "dltSource " size= "10 " multiple style= "width:100% ">
<option value= "0 "> 辽宁 </option>
<option value= "0 "> 黑龙江 </option>
<option value= "0 "> 吉林 </option>
<option value= "0 "> 河北 </option>
<option value= "0 "> 河南 </option>
<option value= "0 "> 江苏 </option>
<option value= "0 "> 浙江 </option>
<option value= "0 "> 海南 </option>
<option value= "0 "> 福建 </option>
<option value= "0 "> 山东 </option>
<option value= "0 "> 青海 </option>
<option value= "0 "> 宁夏 </option>
<option value= "0 "> 内蒙古 </option>
<option value= "0 "> 新疆 </option>
<option value= "0 "> 陕西 </option>
</select>
</td>
<td width= "50 " valign= "middle ">
<p style= "width:100% " align= "center "> <input type= "button " value= "-> " onClick= "Add(document.all.dltSource,frmDisplay.dltTarget) " title= "添加 "> </p>
<p style= "width:100% " align= "center "> <input type= "button " value= "=> " onClick= "AddAll(document.all.dltSource,frmDisplay.dltTarget) " title= "添加全部 "> </p>
<p style= "width:100% " align= "center "> <input type= "button " value= " <- " onClick= "Add(frmDisplay.dltTarget,document.all.dltSource) " title= "删除 "> </p>
<p style= "width:100% " align= "center "> <input type= "button " value= " <= " onClick= "AddAll(frmDisplay.dltTarget,document.all.dltSource) " title= "删除全部 "> </p>
</td>
<td width= "150 ">
<form id= "frmDisplay " action= &q