国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

js 調整select 位置的函數

2019-11-21 01:48:33
字體:
來源:轉載
供稿:網友
 //   排序:向上移動   
  function   Up()   
  ...{  
     var   sel=document.getElementById("selectCheck");  //獲取select
     var   nIndex   =   sel.selectedIndex;   //需要進行操作的select 項的索引
     var   nLen   =   sel.length;   //select 總共項目數
     if   ((nLen<1)||(nIndex==0))   return;   
     if   (nIndex<0)  
     ...{   
        alert("請選擇一個要移動的已選按鈕!");   
        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;   
  }  
  //   排序:向下移動   
  function   Down()  
   ...{   
     var   sel=document.getElementById("selectCheck");   
     var   nIndex   =   sel.selectedIndex;   
     var   nLen   =   sel.length;   
     if   ((nLen<1)||(nIndex==nLen-1))   return;   
     if   (nIndex<0)   
     ...{   
       alert("請選擇一個要移動的已選按鈕!");   
       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;   
   }    
   //移動到最上
   function UpFirst()
   ...{
      var   sel=document.getElementById("selectCheck"); 
      var   nIndex   =   sel.selectedIndex;  
      var   nLen = sel.options.length;
      if   ((nLen<1)||(nIndex==0))   return;   

      if(nIndex<0)
      ...{
          alert("請選擇一個要移動的已選按鈕!");   
          return; 
      }
      var tempValue = document.getElementById("tempValue");//用于臨時存放option的值
      tempValue.value = "";
      for(var k=0;k<nIndex;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<=nIndex;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<1)||(nIndex==nLen))   return;   

      if(nIndex<0)
      ...{
          alert("請選擇一個要移動的已選按鈕!");   
          return; 
      }
      var tempValue = document.getElementById("tempValue");//用于臨時存放option的值
      tempValue.value = "";
      for(var k=nIndex+1;k<nLen;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<nLen;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;
   }
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 木兰县| 衡山县| 淳安县| 武宁县| 什邡市| 绍兴市| 汝城县| 三原县| 长岛县| 阳曲县| 唐山市| 扶沟县| 独山县| 青冈县| 汶上县| 揭东县| 剑河县| 保德县| 洪洞县| 从江县| 罗定市| 黑山县| 灵丘县| 丹寨县| 安远县| 黎城县| 武宁县| 陇西县| 黎平县| 东海县| 江油市| 个旧市| 饶河县| 枣阳市| 河东区| 保德县| 万盛区| 邓州市| 明水县| 大荔县| 桑植县|