chaircat(chaircat) ( ) 信誉:100 Blog 2006-9-25 20:52:09 得分: 0 啊哈...就是把要上移的option跟它上面那一个swapNode()啊~~~-------------- 用swrapNode会有滚动条的问题, 所以我在回贴里用八行代码取代了swrapNode的那一行代码: //theObj.options[i].swapNode(theObj.options[i-1]);// re this and use the following to fix scrollbar error. var tempStr=theObj.options[i-1].value; theObj.options[i-1].value=theObj.options[i].value; theObj.options[i].value=tempStr; tempStr=theObj.options[i-1].text; theObj.options[i-1].text=theObj.options[i].text; theObj.options[i].text=tempStr; theObj.options[i].selected=false; theObj.options[i-1].selected=true;
改为如下。左右移动进行选取,以及选中后上下移动
http://jkisjk.spaces.live.com/blog/cns!758CACE25E89DD3B!355.entry
<option>选项1</option>
<option>选项2</option>
<option>选项3</option>
<option>选项4</option>
<option>选项5</option>
<option>选项6</option>
<option>选项7</option>
<option>选项8</option>
</select><button onclick="changepos(test,-1)">上移</button>
<button onclick="changepos(test,1)">下移</button><SCRIPT LANGUAGE="JavaScript">
<!--
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>
啊哈...就是把要上移的option跟它上面那一个swapNode()啊~~~--------------
用swrapNode会有滚动条的问题,
所以我在回贴里用八行代码取代了swrapNode的那一行代码: //theObj.options[i].swapNode(theObj.options[i-1]);// re this and use the following to fix scrollbar error.
var tempStr=theObj.options[i-1].value;
theObj.options[i-1].value=theObj.options[i].value;
theObj.options[i].value=tempStr;
tempStr=theObj.options[i-1].text;
theObj.options[i-1].text=theObj.options[i].text;
theObj.options[i].text=tempStr;
theObj.options[i].selected=false;
theObj.options[i-1].selected=true;