JQ寫下拉式清單項目移動,還存在2個小BUG(內附效果圖和原始碼)

來源:互聯網
上載者:User

標籤:click   image   tor   val   tle   ext   ted   name   rds   

如下:

實現功能:點擊第一個按鈕,讓選中的對象從左邊移動到右邊;

     點擊第二個按鈕,讓左邊的所有對象移動到右邊;

     點擊第三個按鈕,讓選中的對象從右邊邊移動到左邊;

      點擊第四個按鈕,讓右邊的所有對象移動到左邊。

存在BUG:點擊第一個或者第三個按鈕,不選擇對象也能讓末位的對象移動到另外一個框中;

     選中2個以上的對象,點擊第一或者第三個按鈕,只能移動一個對象到另一邊。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html>    <head>        <title>建立網頁</title>        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />        <meta name="description" content="" />        <meta name="keywords" content="" />        <script type="text/javascript" src="jquery.js"></script>        <style type="text/css">        select{width:130px; height:220px;}        </style>        <script>        //$(selector).append(content) :將content追加到selector選取器內部的最後面        // $(content).appendTo(selector):將content追加到selector選取器內部的最後面                    $(function  () {                                      //當頁面載入完成時;                                              $("input").eq(0).click( function () {        //按下第一個按鈕,觸發函數                         var n =  $("#hebei")[0].selectedIndex;  //擷取被選中的option的下標n                         $("#hebei>option").eq(n).appendTo($("#henan"));  //把下標為n的option移動到henan的下拉式清單中                                                 });                                              $("input").eq(1).click( function () {       //按下第二個按鈕,觸發函數                         $("#hebei>option").appendTo($("#henan"));  //把hebei的option全部移動到henan的下拉式清單中                     });                  $("input").eq(2).click( function () {      //按下第三個按鈕,觸發函數                         var n =  $("#henan")[0].selectedIndex;  //擷取被選中的option的下標n                         $("#henan>option").eq(n).appendTo($("#hebei")); //把下標為n的option移動到hebei的下拉式清單中                     });                    $("input").eq(3).click( function () {    //按下第四個按鈕,觸發函數                         $("#henan>option").appendTo($("#hebei")); //把henan的option全部移動到hebei的下拉式清單中                     });        });        </script>    </head>    <body>        <select id="hebei" multiple="multiple">            <option>石家莊</option>            <option>保定</option>            <option>邯鄲</option>            <option>邢台</option>            <option>衡水</option>        </select>        <select id="henan" multiple="multiple">            <option>鄭州</option>            <option>開封</option>            <option>洛陽</option>            <option>周口</option>            <option>信陽</option>        </select><br /><br />        <input type="button" value="-->">        <input type="button" value="==>" >        <input type="button" value="<--" >        <input type="button" value="<==" >            </body></html>

  

JQ寫下拉式清單項目移動,還存在2個小BUG(內附和原始碼)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.