<script language=javascript>
// 加入已选
function Add() {
var sel1=document.myform.d_b1;
var sel2=document.myform.d_b2;
if (sel1.selectedIndex<0) {
alert("请选择一个待选按钮!");
return;
}
sel2.options[sel2.length]=new Option(sel1.options[sel1.selectedIndex].innerHTML,sel1.options[sel1.selectedIndex].value);
}
// 从已选中删除
function Del() {
var sel=document.myform.d_b2;
var nIndex = sel.selectedIndex;
var nLen = sel.length;
if (nLen<1) return;
if (nIndex<0) {
alert("请选择一个已选按钮!");
return;
}
for (var i=nIndex;i<nLen-1;i++) {
sel.options[i].value=sel.options[i+1].value;
sel.options[i].innerHTML=sel.options[i+1].innerHTML;
}
sel.length=nLen-1;
}
// 排序:向上移动
function Up() {
var sel=document.myform.d_b2;
var nIndex = sel.selectedIndex;
var nLen = sel.length;
if ((nLen<1)||(nIndex==0)) return;
if (nIndex<0) {
alert("请选择一个要移动的已选按钮!");
return;
}
var sValue=sel.options[nIndex].value;
var sHTML=sel.options[nIndex].innerHTML;
sel.options[nIndex].value=sel.options[nIndex-1].value;
sel.options[nIndex].innerHTML=sel.options[nIndex-1].innerHTML;
sel.options[nIndex-1].value=sValue;
sel.options[nIndex-1].innerHTML=sHTML;
sel.selectedIndex=nIndex-1;
}
// 排序:向下移动
function Down() {
var sel=document.myform.d_b2;
var nIndex = sel.selectedIndex;
var nLen = sel.length;
if ((nLen<1)||(nIndex==nLen-1)) return;
if (nIndex<0) {
alert("请选择一个要移动的已选按钮!");
return;
}
var sValue=sel.options[nIndex].value;
var sHTML=sel.options[nIndex].innerHTML;
sel.options[nIndex].value=sel.options[nIndex+1].value;
sel.options[nIndex].innerHTML=sel.options[nIndex+1].innerHTML;
sel.options[nIndex+1].value=sValue;
sel.options[nIndex+1].innerHTML=sHTML;
sel.selectedIndex=nIndex+1;
}
// 提交处理
function checkform() {
var sel=document.myform.d_b2;
var nLen = sel.length;
var str="";
for (var i=0;i<nLen;i++) {
if (i>0) str+="|";
str+=sel.options[i].value;
}
document.myform.d_button.value=str;
return true;
}
</script>
<table border=0 cellpadding=5 cellspacing=0 align=center>
<form action='*****' method=post name=myform onsubmit='return checkform()'>
<tr align=center>
<td>
<select name='d_b1' size=20 style='width:200px' ondblclick='Add()'>
<option value='选项'>选项</option>
......
</select>
</td>
<td>
<input type=button name=b1 value=' → ' onclick='Add()'>
<br>
<br>
<input type=button name=b1 value=' ← ' onclick='Del()'>
</td>
<td>
<select name='d_b2' size=20 style='width:200px' ondblclick='Del()'>
</select>
</td>
<td>
<input type=button name=b3 value='↑' onclick='Up()'>
<br>
<br>
<br>
<input type=button name=b4 value='↓' onclick='Down()'>
</td>
</tr>
<input type=hidden name='d_button' value=''>
<tr>
<td colspan=4 align=right><input type=submit name=b value=' 保存设置 '></td></tr>
</td>
</tr>
</form>
</table>