栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

js 调整select 位置的函数

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

js 调整select 位置的函数

//   排序:向上移动   
  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      ...{
         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      ...{
         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;
   }
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/119448.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号