<script>
function move(bool)
{
if(document.all.mysel.selectedIndex>=0)
{
i=bool=="up"?-1:1;
myvalue=document.all.mysel.options[document.all.mysel.selectedIndex+i].value;
mytext=document.all.mysel.options[document.all.mysel.selectedIndex+i].text;
document.all.mysel.options[document.all.mysel.selectedIndex+i].value=document.all.mysel.options[document.all.mysel.selectedIndex].value;
document.all.mysel.options[document.all.mysel.selectedIndex+i].text=document.all.mysel.options[document.all.mysel.selectedIndex].text;
document.all.mysel.options[document.all.mysel.selectedIndex].value=myvalue;
document.all.mysel.options[document.all.mysel.selectedIndex].text=mytext;
}
}
function set()
{
if(document.all.mysel.selectedIndex==0)
document.all.up.disabled=true;
else
document.all.up.disabled=false;
if(document.all.mysel.selectedIndex==document.all.mysel.options.length-1)
document.all.down.disabled=true;
else
document.all.down.disabled=false;
}
function del()
{
if(document.all.mysel.selectedIndex>=0)
document.all.mysel.options[document.all.mysel.selectedIndex]=null;
}
</script>
<body onload=set()>
<select id=mysel size=4 onchange=set()>
<option value=1 selected>1
<option value=2>2
<option value=3>3
<option value=4>4
</select>
<input type=button value=up id=up onclick=move("up")>
<input type=button value=down id=down onclick=move("down")>
<input type=button value=del id=del onclick=del()>

解决方案 »

  1.   

    只改变选中项
    <script>
    function move(bool)
    {
    if(document.all.mysel.selectedIndex>=0)
    {
    i=bool=="up"?-1:1;
    document.all.mysel.selectedIndex+=i;
    set();
    /*
    myvalue=document.all.mysel.options[document.all.mysel.selectedIndex+i].value;
    mytext=document.all.mysel.options[document.all.mysel.selectedIndex+i].text;
    document.all.mysel.options[document.all.mysel.selectedIndex+i].value=document.all.mysel.options[document.all.mysel.selectedIndex].value;
    document.all.mysel.options[document.all.mysel.selectedIndex+i].text=document.all.mysel.options[document.all.mysel.selectedIndex].text;
    document.all.mysel.options[document.all.mysel.selectedIndex].value=myvalue;
    document.all.mysel.options[document.all.mysel.selectedIndex].text=mytext;
    */
    }
    }
    function set()
    {
    if(document.all.mysel.selectedIndex==0)
    document.all.up.disabled=true;
    else
    document.all.up.disabled=false;
    if(document.all.mysel.selectedIndex==document.all.mysel.options.length-1)
    document.all.down.disabled=true;
    else
    document.all.down.disabled=false;
    }
    function del()
    {
    if(document.all.mysel.selectedIndex>=0)
    document.all.mysel.options[document.all.mysel.selectedIndex]=null;
    }
    </script>
    <body onload=set()>
    <select id=mysel size=4 onchange=set()>
    <option value=1 selected>1
    <option value=2>2
    <option value=3>3
    <option value=4>4
    </select>
    <input type=button value=up id=up onclick=move("up")>
    <input type=button value=down id=down onclick=move("down")>
    <input type=button value=del id=del onclick=del()>
      

  2.   

    <script>
    function move(bool)
    {
    if(document.all.mysel.selectedIndex>=0)
    {
    i=bool=="up"?-1:1;
    myvalue=document.all.mysel.options[document.all.mysel.selectedIndex+i].value;
    mytext=document.all.mysel.options[document.all.mysel.selectedIndex+i].text;
    document.all.mysel.options[document.all.mysel.selectedIndex+i].value=document.all.mysel.options[document.all.mysel.selectedIndex].value;
    document.all.mysel.options[document.all.mysel.selectedIndex+i].text=document.all.mysel.options[document.all.mysel.selectedIndex].text;
    document.all.mysel.options[document.all.mysel.selectedIndex].value=myvalue;
    document.all.mysel.options[document.all.mysel.selectedIndex].text=mytext;
    document.all.mysel.selectedIndex+=i;
    set();
    }
    }
    function set()
    {
    if(document.all.mysel.selectedIndex==0)
    document.all.up.disabled=true;
    else
    document.all.up.disabled=false;
    if(document.all.mysel.selectedIndex==document.all.mysel.options.length-1)
    document.all.down.disabled=true;
    else
    document.all.down.disabled=false;
    }
    function del()
    {
    if(document.all.mysel.selectedIndex>=0)
    document.all.mysel.options[document.all.mysel.selectedIndex]=null;
    }
    </script>
    <body onload=set()>
    <select id=mysel size=4 onchange=set()>
    <option value=1 selected>1
    <option value=2>2
    <option value=3>3
    <option value=4>4
    </select>
    <input type=button value=up id=up onclick=move("up")>
    <input type=button value=down id=down onclick=move("down")>
    <input type=button value=del id=del onclick=del()>