<select id=test size=7 οnmοusedοwn="this.dragenable=true;this.setCapture();curOption=this.options[getIndex(this)]" οnmοusemοve="if(this.dragenable==true)swapOption(this)" οnmοuseup="this.dragenable=false;this.releaseCapture();this.releaseCapture();"><option>选项一</option><option>选项二</option><option>选项三</option><option>选项四</option><option>选项五</option><option>选项六</option><option>选项七</option></select>
<button οnclick="up(test)">向上</button>
<button οnclick="down(test)">向下</button>
<script>
var curOption=new Option();
function up(obj)
{
if(obj.selectedIndex!=-1) {
var obj1=obj.options(obj.selectedIndex);
if (obj.selectedIndex>0)
obj1.swapNode(obj1.previousSibling);
}
}
function down(obj)
{
if(obj.selectedIndex!=-1) {
var obj1=obj.options(obj.selectedIndex);
if (obj.selectedIndex<obj.options.length-1)
obj1.swapNode(obj1.nextSibling);
}
}
function swapOption(obj) {
if(curOption!=null && curOption!=obj.options[getIndex(obj)] && getIndex(obj)>-1 && getIndex(obj)<obj.size)curOption.swapNode(obj.options[getIndex(obj)]);
}
function getIndex(obj) {
var theIndex=Math.floor((event.offsetY+2)/(obj.offsetHeight/obj.size));
if(theIndex<0)theIndex=0;
else if(theIndex>obj.options.length)theIndex=obj.options.length;
return theIndex;
}
</script>