Home > Web Front-end > JS Tutorial > js function to adjust select position_javascript skills

js function to adjust select position_javascript skills

WBOY
Release: 2016-05-16 19:06:05
Original
996 people have browsed it

// Sorting: Move upward
Function up ()
... {
var sel = document.GetelementByid ("Selectcheck"); // Get selection
var nindex = sel.selectIndex;/ /The index of the select item that needs to be operated
var nLen = sel.length; //The total number of select items
if ((nLen if (nIndex ...{
alert("Please select a selected button to move!");
return;
} }
var sValue=sel.options[ nIndex].value;
var sHTML=sel.options[nIndex].innerHTML;
sel.options[nIndex].value=sel.options[nIndex-1].value;
sel.options[ nIndex].innerHTML=sel.options[nIndex-1].innerHTML; > sel.selectedIndex=nIndex-1; );
var nIndex = sel.selectedIndex;
var nLen = sel.length;
if ((nLen if ( nIndex ...{ 
  alert("Please select a selected button to move! ");
return; }
var sValue=sel.options[nIndex].value;
var sHTML=sel.options[nIndex].innerHTML; sel.options[nIndex ].value=sel.options[nIndex 1].value; 
 sel.options[nIndex].innerHTML=sel.options[nIndex 1].innerHTML; 
 sel.options[nIndex 1].value=sValue ; sel.options[nIndex 1].innerHTML=sHTML; sel.selectedIndex=nIndex 1;
}
//Move to the top
function UpFirst()
. . .{
var sel=document.getElementById("selectCheck");
var nIndex = sel.selectedIndex;
var nLen = sel.options.length;
if ((nLen

if(nIndex ...{
alert("Please select a selected button to move!");   
          return; 
      }
      var tempValue = document.getElementById("tempValue");//用于临时存放option的值
      tempValue.value = "";
      for(var k=0;k      ...{
         tempValue.value  =  sel.options[k].value ";";
      }
      var arrValue = tempValue.value.split(';');
      var   sValue=sel.options[nIndex].value;   
      var   sHTML=sel.options[nIndex].innerHTML;   
      sel.options[0].value = sValue;
      sel.options[0].innerHTML = sHTML;

     for(var j=1;j     ...{
       sel.options[j].value = arrValue[j-1];
       sel.options[j].innerHTML = arrValue[j-1];
     }
      sel.selectedIndex = 0;
   }
   //移动到最后
   function DownLast()
   ...{
      var   sel=document.getElementById("selectCheck"); 
      var   nIndex   =   sel.selectedIndex;  
      var   nLen = sel.options.length;
      if   ((nLen
      if(nIndex      ...{
          alert("请选择一个要移动的已选按钮!");   
          return; 
      }
      var tempValue = document.getElementById("tempValue");//用于临时存放option的值
      tempValue.value = "";
      for(var k=nIndex 1;k      ...{
         tempValue.value  =  sel.options[k].text ";";
      }
      var arrValue = tempValue.value.split(';');
      var   sValue=sel.options[nIndex].value;   
      var   sHTML=sel.options[nIndex].innerHTML;   

    
     for(var j=nIndex;j     ...{
       sel.options[j].value = arrValue[j-nIndex ];
       sel.options[j].innerHTML = arrValue[j-nIndex];
     }

      sel.options[nLen-1].value = sValue;
      sel.options[nLen-1].innerHTML = sHTML;
      sel.selectedIndex = nLen-1;
   }

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template