<form name=”myform” method=”post” >
<select name=”hostlist1” size=”15” multiple=”multiple”>
<option >…..</option>
</select>
< select name=”hostlist2” size=”15”
multiple=”multiple”>
</select>
<input name=”addbutton” type=”button” value=”添加” onclick=”dealAgent(document.myform.hostlist2, document.myform.hostlist1)”/>
<input name=”addbutton” type=”button” value=”删除” onclick=”dealAgent(document.myform.hostlist1, document.myform.hostlist2)”/>
<input type=”button” value=”上移”onclick="changepos(hostlist2,-1)" type="button">
<input type=”button” value=”下移”onclick="changepos(hostlist2,1)" type="button">
<input name=”hostvalue” type=”hidden”/>
</form>
<script>
function dealAgent(hostlist1,hostlist2)
{
for(var i=0;i<hostlist1.options.length;i++)
{
if(hostlist1.options[i].selected)
{
var host=hostlist1.options[i];
hostlist2.options.add(new Option(host.text,host.value));
hostlist1.remove(i);
i=i-1;
}
}
document.myform.hostvalue.value=getValue(document.myform.hostlist2);
//document.myform.hostvalue.value=getValue(document.myform.hostlist2);
}
function getValue(hostlist2){
var hostValue="";
if(hostlist2.options.length!=0)
hostValue+=hostlist2.options[0].value;
for(var i=1;i<hostlist2.options.length;i++){
hostValue +=","+hostlist2.options[i].value;
}
return hostValue;
}
function changepos(obj,index)
{
if(index==-1){
if (obj.selectedIndex>0){
obj.options(obj.selectedIndex).swapNode(obj.options(obj.selectedIndex-1))
}
}
else if(index==1){
if (obj.selectedIndex<obj.options.length-1){
obj.options(obj.selectedIndex).swapNode(obj.options(obj.selectedIndex+1))
}
}
}
</script>
左侧下拉框中的内容点击按钮移到右侧下拉框,布布扣,bubuko.com
原文:http://www.cnblogs.com/bmdjing/p/3591147.html