动态改变select中option的次序
<script>
<!--
functionaddOption() {
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);
}
}
functionupOption(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]=newOption(sName,sValue);
frm.select1.options[id]=newOption(sName2,sValue2);
frm.select1.options.selectedIndex = (id-1);
}
}
functiondownOption(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)]=newOption(sName,sValue);
frm.select1.options[id]=newOption(sName2,sValue2);
frm.select1.options.selectedIndex = (id+1);
}
}
//-->
</script>
<bodyonload=addOption();>
<formname=frm>
<buttononclick="upOption(select1.selectedIndex);"><fontface="Webdings">5</font></button>
<selectid="select1" name=select1" multiple size="10"width=100 onchange=alert(this.value)></select>
<buttononclick="downOption(select1.selectedIndex);"><fontface="Webdings">6</font></button>
</form>