js 调整select 位置的函数

瑾誠

瑾誠

2016-02-19 09:02

图老师设计创意栏目是一个分享最好最实用的教程的社区,我们拥有最用心的各种教程,今天就给大家分享js 调整select 位置的函数的教程,热爱PS的朋友们快点看过来吧!
 //   排序:向上移动   
  function   Up()   
  ...{  
     var   sel=document.getElementById("selectCheck");  //获取select
     var   nIndex   =   sel.selectedIndex;   //需要进行操作的select 项的索引
     var   nLen   =   sel.length;   //select 总共项目数
     if   ((nLen1)||(nIndex==0))   return;   
     if   (nIndex0)  
     ...{   
        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   ((nLen1)||(nIndex==nLen-1))   return;   
     if   (nIndex0)   
     ...{   
       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   ((nLen1)||(nIndex==0))   return;   

      if(nIndex0)
      ...{
          alert("请选择一个要移动的已选按钮!");   
          return; 
      }
      var tempValue = document.getElementById("tempValue");//用于临时存放option的值
      tempValue.value = "";
      for(var k=0;knIndex;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   ((nLen1)||(nIndex==nLen))   return;   

      if(nIndex0)
      ...{
          alert("请选择一个要移动的已选按钮!");   
          return; 
      }
      var tempValue = document.getElementById("tempValue");//用于临时存放option的值
      tempValue.value = "";
      for(var k=nIndex+1;knLen;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;jnLen;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;
   }
展开更多 50%)
分享

猜你喜欢

js 调整select 位置的函数

Web开发
js 调整select 位置的函数

JQuery SELECT单选模拟jQuery.select.js

Web开发
JQuery SELECT单选模拟jQuery.select.js

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

JS匿名函数

Web开发
JS匿名函数

JS教程:匿名函数

Web开发
JS教程:匿名函数

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

JS对HTML标签select的操作

Web开发
JS对HTML标签select的操作

js几个不错的函数 $$()

Web开发
js几个不错的函数 $$()

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

选择粘贴格式,让Excel也能玩内容截图

选择粘贴格式,让Excel也能玩内容截图

ajax 防止用户反复提交的2种解决方案

ajax 防止用户反复提交的2种解决方案
下拉加载更多内容 ↓