手写getSelectItem、getSelectItemIndex方法
function setToFirst(list){
var obj=getSelectItem(list);
var index=getSelectItemIndex(list);
if(index==0){return;}
list.add(new Option(obj.innerText,obj.value),0);
list.remove(list.length-1);
list.selectedIndex=0;
}
function setToLast(list){
var obj=getSelectItem(list);
var index=getSelectItemIndex(list);
if(index==list.length-1){return;}
list.add(new Option(obj.innerText,obj.value),list.length);
list.remove(getSelectItemIndex(list));
list.selectedIndex=list.length-1;
}
function setToUp(list){
var index=getSelectItemIndex(list);
var obj=getSelectItem(list);
if(index>0){
list.add(new Option(obj.innerText,obj.value),index-1);
list.remove(index+1);
list.selectedIndex=index-1;
}
}
function setToDown(list){
var index=getSelectItemIndex(list);
var obj=getSelectItem(list);
if(index<list.length-1){
list.add(new Option(obj.innerText,obj.value),index+2);
list.remove(index);
list.selectedIndex=index+1;
}
}
其实实现这些使用jQuery是相当简单的,以前自己会写这么去写