这篇文章介绍了JS下拉框内容左右移动效果的具体实现方法
有需要的朋友可以参考一下
复制代码 代码如下:
<HTML>
<HEAD>
<TITLE>选择下拉菜单</TITLE>
<META NAME="Description" CONTENT="Power by hill">
<meta httpequiv="ContentType" content="text/html; charset=utf" />
</HEAD>
<BODY>
<p>选定一项或多项然后点击添加或移除(按住shift或ctrl可以多选)或在选择项上双击进行添加和移除</p>
<form method="post" name="myform">
<table border="" width="">
<tr>
<td width="%">
<select style="WIDTH:%" multiple name="list" size="" ondblclick="moveOption(documentmyformlist documentmyformlist)">
<option value="北京">北京</option>
<option value="上海">上海</option>
<option value="山东">山东</option>
<option value="安徽">安徽</option>
<option value="重庆">重庆</option>
<option value="福建">福建</option>
<option value="甘肃">甘肃</option>
<option value="广东">广东</option>
<option value="广西">广西</option>
<option value="贵州">贵州</option>
<option value="海南">海南</option>
<option value="河北">河北</option>
<option value="黑龙江">黑龙江</option>
</select>
</td>
<td width="%" align="center">
<input type="button" value="添加" onclick="moveOption(documentmyformlist documentmyformlist)"><br/>
<br/>
<input type="button" value="删除" onclick="moveOption(documentmyformlist documentmyformlist)">
</td>
<td width="%">
<select style="WIDTH:%" multiple name="list" size="" ondblclick="moveOption(documentmyformlist documentmyformlist)">
</select>
</td>
<td>
<button onclick="changepos(list)" type="button">上移</button>
<br/>
<button onclick="changepos(list)" type="button">下移</button>
</td>
</tr>
</table>
值<input type="text" name="city" size="">
</form>
<script language="JavaScript">
function moveOption(e e){
try{
for(var i=;i<eoptionslength;i++){
if(eoptions[i]selected){
var e = eoptions[i];
eoptionsadd(new Option(etext evalue));
eremove(i);
ii=i
}
}
documentmyformcityvalue=getvalue(documentmyformlist);
}
catch(e){}
}
function getvalue(geto){
var allvalue = "";
for(var i=;i<getooptionslength;i++){
allvalue +=getooptions[i]value + "";
}
return allvalue;
}
function changepos(objindex)
{
if(index==){
if (objselectedIndex>){
objoptions(objselectedIndex)swapNode(objoptions(objselectedIndex))
}
}
else if(index==){
if (objselectedIndex<objoptionslength){
objoptions(objselectedIndex)swapNode(objoptions(objselectedIndex+))
}
}
}
</script>
</BODY>
</HTML>