最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于javascript實現(xiàn)listbox左右移動

 更新時間:2016年01月29日 09:26:59   作者:沸羊羊一個  
這篇文章主要介紹了基于javascript實現(xiàn)listbox左右移動的相關資料,以一個完整的實例代碼分析了js實現(xiàn)listbox左右移動的相關技巧,感興趣的小伙伴們可以參考一下

本文實例講解了javascript實現(xiàn)listbox左右移動的詳細代碼,分享給大家供大家參考,具體內容如下

效果圖:

具體代碼:

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<title>listbox左右移動</title> 
</head> 
 
<body> 
 
<div style="background-color:#CCC; width:450px; height:300px; margin:150px,0,0,450px; border:1px solid"> 
  <table align="center" width="285" height="169" bgcolor="#99CCFF"> 
  <tr> 
   <td width="100"> 
    <select name="first" id="first" size="10" multiple="multiple" style="background-color:#3FC;"> 
     <option value="選項1">選項1</option> 
     <option value="選項2">選項2</option> 
     <option value="選項3">選項3</option> 
     <option value="選項4">選項4</option> 
     <option value="選項5">選項5</option> 
     <option value="選項6">選項6</option> 
     <option value="選項7">選項7</option> 
     <option value="選項8">選項8</option> 
    </select> 
   </td> 
   <td width="85" valign="middle"> 
    <input name="add" id="add" type="button" value="--->"/> 
    <input name="add_all" id="add_all" type="button" value="===>"/> 
    <input name="remove" id="remove" type="button" value="<---"/> 
    <input name="remove_all" id="remove_all" type="button" value="<==="/> 
   </td> 
   <td width="100" align="left"> 
    <select name="second" id="second" size="10" multiple="multiple" style="background-color:#3FC;"> 
    <option value="選項9">選項9</option> 
    </select> 
   </td> 
  </tr> 
  </table> 
</div> 
 
</body> 
<script type="text/javascript"> 
 //左移右 
  
  /*<input name="add" id="add" type="button" value="--->"/>*/ 
  document.getElementById("add").onclick = function add() 
  { 
   var firstSel = document.getElementById("first"); 
   var option = firstSel.getElementsByTagName("option"); 
   //javascript的數(shù)組是動態(tài)數(shù)組,長度是可以變的。 
   //所以先取得下拉列表的長度,避免option被移走后長度變小,導致后面循環(huán)終止,出現(xiàn)beg 
   var oplength=option.length; 
   var secondSel = document.getElementById("second"); 
   for(i=0;i<oplength;i++) 
   { 
     /* 
      selectedIndex: 該下標返回下拉列表的索引值 
      注: 如果有多個被選中的情況下,永遠返回第一個選中的索引值,索引最小的那個 
         如果沒有被選中的情況下,返回-1 
         selectedIndex是<select>的屬性 
     */ 
     if(firstSel.selectedIndex!=-1) 
     { 
       secondSel.appendChild(option[firstSel.selectedIndex]); 
     } 
   } 
    
  } 
   
  /*<input name="add_all" id="add_all" type="button" value="===>"/>*/ 
  document.getElementById("add_all").onclick = function addAll() 
  { 
   var firstSel = document.getElementById("first"); 
   var option = firstSel.getElementsByTagName("option"); 
   //javascript的數(shù)組是動態(tài)數(shù)組,長度是可以變的。 
   //所以先取得下拉列表的長度,避免option被移走后長度變小,導致后面循環(huán)終止,出現(xiàn)beg 
   var oplength=option.length; 
   var secondSel = document.getElementById("second"); 
   for(i=0;i<oplength;i++) 
   { 
    /*因為javascript的數(shù)組是動態(tài)數(shù)組,長度是可以變的。所以當移走全部把數(shù) 
    組的值移走(一個一個的移走,數(shù)組長度馬上-1,所以數(shù)組下標也是-1.因次我們要把每次移的是走下標為0的那個 
    數(shù),這樣才保證可以全部移走)*/ 
    secondSel.appendChild(option[0]); 
   } 
  } 
   
  /*雙擊后把option移到右邊*/ 
  document.getElementById("first").ondblclick = function dblclick() 
  { 
    /*方法一*/ 
    /* 
   var firstSel = document.getElementById("first"); 
   var option = firstSel.getElementsByTagName("option"); 
   //javascript的數(shù)組是動態(tài)數(shù)組,長度是可以變的。 
   //所以先取得下拉列表的長度,避免option被移走后長度變小,導致后面循環(huán)終止,出現(xiàn)beg 
   var oplength=option.length; 
   var secondSel = document.getElementById("second"); 
   for(i=0;i<oplength;i++) 
   { 
      //雙擊可以看成:第一次點擊選中,第二次點擊移動 
      secondSel.appendChild(option[firstSel.selectedIndex]);   
   } 
   */ 
    
   /*方法二*/ 
   /* 
   this: this表示document.getElementById("first")  下拉列表 
      this.selectedIndex表示下拉列表選中的項 
   */ 
    var secondSel = document.getElementById("second"); 
    secondSel.appendChild(this[this.selectedIndex]); 
  } 
   
   
   
   
  //右移左 
   
   
  /*<input name="remove" id="remove" type="button" value="<---"/>*/ 
  document.getElementById("remove").onclick = function remove() 
  { 
   var secondSel = document.getElementById("second"); 
   var firstSel = document.getElementById("first"); 
   var option = secondSel.getElementsByTagName("option"); 
   //javascript的數(shù)組是動態(tài)數(shù)組,長度是可以變的。 
   //所以先取得下拉列表的長度,避免option被移走后長度變小,導致后面循環(huán)終止,出現(xiàn)beg 
   var oplength=option.length; 
   for(i=0;i<oplength;i++) 
   { 
     /* 
      selectedIndex: 該下標返回下拉列表的索引值 
      注: 如果有多個被選中的情況下,永遠返回第一個選中的索引值,索引最小的那個 
         如果沒有被選中的情況下,返回-1 
         selectedIndex是<select>的屬性 
     */ 
     if(secondSel.selectedIndex!=-1) 
     { 
       firstSel.appendChild(option[secondSel.selectedIndex]); 
     } 
   } 
    
  } 
   
  /*<input name="remove_all" id="remove_all" type="button" value="<==="/>*/ 
  document.getElementById("remove_all").onclick = function remove_all() 
  { 
   var secondSel = document.getElementById("second"); 
   var firstSel = document.getElementById("first"); 
   var option = secondSel.getElementsByTagName("option"); 
   //javascript的數(shù)組是動態(tài)數(shù)組,長度是可以變的。 
   //所以先取得下拉列表的長度,避免option被移走后長度變小,導致后面循環(huán)終止,出現(xiàn)beg 
   var oplength=option.length; 
   for(i=0;i<oplength;i++) 
   { 
    /*因為javascript的數(shù)組是動態(tài)數(shù)組,長度是可以變的。所以當移走全部把數(shù) 
    組的值移走(一個一個的移走,數(shù)組長度馬上-1,所以數(shù)組下標也是-1.因次我們要把每次移的是走下標為0的那個 
    數(shù),這樣才保證可以全部移走)*/ 
    firstSel.appendChild(option[0]); 
   } 
  } 
   
  /*雙擊后把option移到右邊*/ 
  document.getElementById("second").ondblclick = function dblclick() 
  { 
    /*方法一*/ 
    /* 
   var secondSel = document.getElementById("second"); 
   var firstSel = document.getElementById("first"); 
   var option = secondSel.getElementsByTagName("option"); 
   //javascript的數(shù)組是動態(tài)數(shù)組,長度是可以變的。 
   //所以先取得下拉列表的長度,避免option被移走后長度變小,導致后面循環(huán)終止,出現(xiàn)beg 
   var oplength=option.length; 
   for(i=0;i<oplength;i++) 
   { 
      //雙擊可以看成:第一次點擊選中,第二次點擊移動 
      firstSel.appendChild(option[secondSel.selectedIndex]);   
   } 
   */ 
    
   /*方法二*/ 
   /* 
   this: this表示document.getElementById("second")  下拉列表 
      this.selectedIndex表示下拉列表選中的項 
   */ 
    var firstSel = document.getElementById("first"); 
    firstSel.appendChild(this[this.selectedIndex]); 
  } 
</script> 
</html> 

代碼注釋很詳細,希望可以幫到大家。

以上就是本文的全部內容,希望對大家學習javascript程序設計有所幫助。

相關文章

  • es6和commonJs的區(qū)別解析

    es6和commonJs的區(qū)別解析

    這篇文章主要介紹了es6和commonJs的區(qū)別,ES6的模塊化規(guī)范更加先進、靈活,能夠適應更多的應用場景,而CommonJS則更加簡單、易用,廣泛應用于Node.js開發(fā)中,在實際應用中,可以根據(jù)具體情況選擇使用不同的模塊化方案,需要的朋友可以參考下
    2023-03-03
  • JavaScript enum枚舉類型定義及使用方法

    JavaScript enum枚舉類型定義及使用方法

    這篇文章主要介紹了JavaScript enum枚舉類型定義及使用方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-05-05
  • js時間控件只顯示年月

    js時間控件只顯示年月

    本文詳細介紹了js時間控件只顯示年月的方法。具有一定的參考價值,下面跟著小編一起來看下吧
    2017-01-01
  • 微信小程序使用uni-app實現(xiàn)首頁搜索框導航欄功能詳解

    微信小程序使用uni-app實現(xiàn)首頁搜索框導航欄功能詳解

    這篇文章主要介紹了微信小程序使用uni-app實現(xiàn)首頁搜索框導航欄功能,uni-app?是一個使用?Vue.js?(opens?new?window)開發(fā)所有前端應用的框架,開發(fā)者編寫一套代碼,可發(fā)布到iOS、Android、Web(響應式)、以及各種小程序
    2022-10-10
  • 超鏈接怎么正確調用javascript函數(shù)

    超鏈接怎么正確調用javascript函數(shù)

    本文介紹使用超鏈接調用javasript函數(shù)且不會影響GIF圖片動畫的方法,有遇到相同問題的小伙伴可以參考一下。
    2016-05-05
  • Bootstrap3多級下拉菜單

    Bootstrap3多級下拉菜單

    這篇文章主要為大家詳細介紹了Bootstrap3多級下拉菜單的相關資料,需引用bootstrap.min.css和bootstrap.min.css.js,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-02-02
  • Scala解析Json字符串的實例詳解

    Scala解析Json字符串的實例詳解

    這篇文章主要介紹了 Scala解析Json字符串的實例詳解的相關資料,希望通過本文能幫助到大家,讓大家學習理解這部分內容,需要的朋友可以參考下
    2017-10-10
  • js立即執(zhí)行函數(shù): (function ( ){})( ) 與 (function ( ){}( )) 有什么區(qū)別?

    js立即執(zhí)行函數(shù): (function ( ){})( ) 與 (function ( ){}( )) 有什么區(qū)別?

    這篇文章主要介紹了js立即執(zhí)行函數(shù): (function ( ){})( ) 與 (function ( ){}( )) 有什么區(qū)別,需要的朋友可以參考下
    2015-11-11
  • IE6 fixed的完美解決方案

    IE6 fixed的完美解決方案

    IE7已經支持position:fixed了,而我們的IE6呢?還繼續(xù)使用js事件?消耗資源,破壞結構,畫面閃耀。
    2011-03-03
  • 基于JavaScript實現(xiàn)的插入排序算法分析

    基于JavaScript實現(xiàn)的插入排序算法分析

    這篇文章主要介紹了基于JavaScript實現(xiàn)的插入排序算法,結合實例形式詳細分析了插入排序的原理、操作步驟及javascript相關實現(xiàn)技巧與注意事項,需要的朋友可以參考下
    2017-04-04

最新評論

虹口区| 灌阳县| 渭源县| 临沂市| 汨罗市| 云梦县| 锡林郭勒盟| 家居| 新源县| 当涂县| 公安县| 湖口县| 海安县| 察雅县| 奎屯市| 临邑县| 达州市| 桐柏县| 探索| 廉江市| 和平县| 宿松县| 永顺县| 石棉县| 崇明县| 富源县| 镇平县| 勐海县| 江都市| 冕宁县| 江陵县| 广西| 洮南市| 宣城市| 伊川县| 皮山县| 富裕县| 北票市| 罗山县| 东方市| 黔西县|