function (objName,sourceIndex,targetIndex){
var text1,text2,value1,value2;
text1=objName.options[sourceIndex].text;
value1=objName.options[sourceIndex].value;
text2=objName.options[targetIndex].text;
value2=objName.options[targetIndex].value;
objName.options[sourceIndex]=new Option(text2,value2);
objName.options[targetIndex]=new Option(text1,value1);
}
参数是列表框名称、源列表项索引值,目标列表项索引值。
上移和下移只需要交换源列表项索引值和目标列表项索引值就可以了。
var text1,text2,value1,value2;
text1=objName.options[sourceIndex].text;
value1=objName.options[sourceIndex].value;
text2=objName.options[targetIndex].text;
value2=objName.options[targetIndex].value;
objName.options[sourceIndex]=new Option(text2,value2);
objName.options[targetIndex]=new Option(text1,value1);
}
参数是列表框名称、源列表项索引值,目标列表项索引值。
上移和下移只需要交换源列表项索引值和目标列表项索引值就可以了。
var theIndex=window.PE42.selSubmit.selectedIndex;;
var FirIndex=theIndex-1;
var lenghtSel=window.PE42.selSubmit.length;
if(lenghtSel!=0){
if(theIndex<0){
alert("请您先选择一个要移动的栏目...");
}else{
if(theIndex==0){
alert("已经是最前面了...")
}else{
var valF=window.PE42.all("selSubmit")(FirIndex).value; //前一个option的值
var valT=window.PE42.all("selSubmit")(theIndex).value; //当前option的值
var innerTextF=window.PE42.all("selSubmit")(FirIndex).innerText; //前一个option的显示内容
var innerTextT=window.PE42.all("selSubmit")(theIndex).innerText; //当前option的显示内容
window.PE42.all("selSubmit")(theIndex).innerText=innerTextF; //改变显示顺序
window.PE42.all("selSubmit")(FirIndex).innerText=innerTextT; window.PE42.all("selSubmit")(theIndex).value=valF; //改变select的值
window.PE42.all("selSubmit")(FirIndex).value=valT; window.PE42.selSubmit.selectedIndex=FirIndex
}
}
}else{
alert("没有可前移的视图项目,请新增一个...");
}
}
function btnBackward_onclick(){ var theIndex=window.PE42.selSubmit.selectedIndex;
var maxIndex=document.all("selSubmit").length-1;
var lenghtSel=window.PE42.selSubmit.length;
var LstIndex=theIndex+1;
if(lenghtSel!=0){
if(theIndex<0){
alert("请您先选择一个要移动的栏目...");
}else{
if(theIndex==maxIndex){
alert("已经是最后面了...")
}else{
var valL=window.PE42.all("selSubmit")(LstIndex).value; //后一个option的值
var valT=window.PE42.all("selSubmit")(theIndex).value; //当前option的值
var innerTextL=window.PE42.all("selSubmit")(LstIndex).innerText; //后一个option的显示内容
var innerTextT=window.PE42.all("selSubmit")(theIndex).innerText; //当前option的显示内容
window.PE42.all("selSubmit")(LstIndex).innerText=innerTextT; //改变显示顺序
window.PE42.all("selSubmit")(theIndex).innerText=innerTextL;
window.PE42.all("selSubmit")(LstIndex).value=valT; //改变select的值
window.PE42.all("selSubmit")(theIndex).value=valL;
window.PE42.selSubmit.selectedIndex=LstIndex
}
}
}else{
alert("没有可后移的视图项目,请新增一个...");
}
}
<!--
function addOption() {
for(var i=0;i<10;i++) {
var sName = "Name" + i;
var sValue = "value" + i;
var oOption = document.createElement('OPTION');
oOption.text = sName;
oOption.value = sValue;
document.forms[0].select1.options.add(oOption);
}
}function upOption(id){
var frm = document.forms[0];
if(id!=0){
var sName = frm.select1.options[id].text;
var sValue = frm.select1.options[id].value;
var sName2 = frm.select1.options[id-1].text;
var sValue2 = frm.select1.options[id-1].value;
frm.select1.options[id-1]=new Option(sName,sValue);
frm.select1.options[id]=new Option(sName2,sValue2);
frm.select1.options.selectedIndex = (id-1);
}
}function downOption(id){
var frm = document.forms[0];
var s = frm.select1.options.length-1;
if(id!=s){
var sName = frm.select1.options[id].text;
var sValue = frm.select1.options[id].value;
var sName2 = frm.select1.options[parseInt(id+1)].text;
var sValue2 = frm.select1.options[parseInt(id+1)].value;
frm.select1.options[parseInt(id+1)]=new Option(sName,sValue);
frm.select1.options[id]=new Option(sName2,sValue2);
frm.select1.options.selectedIndex = (id+1);
}
}
//-->
</script><body onload=addOption();>
<form>
<button onclick="upOption(select1.selectedIndex);"><font face="Webdings">5</font></button>
<select id="select1" name=select1" multiple size="10" width=100 onchange=alert(this.value)></select>
<button onclick="downOption(select1.selectedIndex);"><font face="Webdings">6</font></button>
</form>
</form><script>
function moveSelected(select, down)
{
if (select.selectedIndex != -1) {
if (down) {
if (select.selectedIndex != select.options.length - 1)
var i = select.selectedIndex + 1;
else
return;
}
else {
if (select.selectedIndex != 0)
var i = select.selectedIndex - 1;
else
return;
}
var swapOption = new Object();
swapOption.text = select.options[select.selectedIndex].text;
swapOption.value = select.options[select.selectedIndex].value;
swapOption.selected = select.options[select.selectedIndex].selected;
swapOption.defaultSelected = select.options[select.selectedIndex].defaultSelected;
for (var property in swapOption)
select.options[select.selectedIndex][property] = select.options[i][property];
for (var property in swapOption)
select.options[i][property] = swapOption[property];
}
}</script>
<head>
<script>
function moveUp(oSelect)
{
try{
var currIndex = oSelect.selectedIndex;
if (currIndex == 0) {alert('已经是最上面了,不能在上移了!'); return false;}
var tmpOpt = new Option(mySelect.value,mySelect.value);
oSelect.add(tmpOpt,currIndex-1);
oSelect.options.remove(currIndex+1);
oSelect.selectedIndex = currIndex - 1;
}
catch(x){alert('哥们,你没选中要移动的对象')}
}function moveDown(oSelect)
{ try{
var currIndex = oSelect.selectedIndex;
if (currIndex == oSelect.options.length-1) {alert('已经是最下面了,不能再下移了!'); return false;}
var tmpOpt = new Option(mySelect.value,mySelect.value);
oSelect.add(tmpOpt,currIndex+2);
oSelect.options.remove(currIndex);
oSelect.selectedIndex = currIndex+1;
}
catch(x){alert('哥们,你没选中要移动的对象')}
}</script>
</head><body>
<select id=mySelect multiple size="9">
<option value='aaaaa'>aaaaa</option>
<option value='bbbbb'>bbbbb</option>
<option value='ccccc'>ccccc</option>
<option value='ddddd'>ddddd</option>
<option value='eeeee'>eeeee</option>
<option value='fffff'>fffff</option>
<option value='ggggg'>ggggg</option>
<option value='hhhhh'>hhhhh</option>
<option value='iiiii'>iiiii</option>
</select><br><button onclick="moveUp(mySelect)">moveUp</button>
<button onclick="moveDown(mySelect)">moveDown</button>
</select>
</body>
</html>