Jquery 兩個select多選控制項中項的移動

來源:互聯網
上載者:User

<html><head>    <link href="${ctx}/css/style.css" rel="stylesheet"type="text/css" />    <script src="${ctx}/lib/jquery/jquery-1.5.2.min.js" type="text/javascript"></script><script type="text/javascript"> /**   *動態給左邊的下拉式清單建立選項   *具體情況可以從資料庫讀取資料動態建立選項   */ $(document).ready(function(){      for(var i=1;i<=5;i++)      {      $("#fb_list").append("<option value='"+i+"'>公開招標小型機採購00"+i+"</option>");       }  })  $(function(){    $("#add").click(function(){         if($("#fb_list option:selected").length>0)         {             $("#fb_list option:selected").each(function(){                $("#select_list").append("<option value='"+$(this).val()+"'>"+$(this).text()+"</option");               $(this).remove();              })         }         else        {             alert("請選擇要添加的分包!");         }     })  })  $(function(){        $("#delete").click(function(){             if($("#select_list option:selected").length>0)             {                 $("#select_list option:selected").each(function(){                       $("#fb_list").append("<option value='"+$(this).val()+"'>"+$(this).text()+"</option");                      $(this).remove();                  })             }             else            {                 alert("請選擇要刪除的分包!");             }       })  }) //提交按扭擷取左右的options所有值傳給幕後處理function sel(){ var obj = document.getElementById('fb_list');  var str="";          for(var i=0;i<obj.options.length;i++)     {         if(str.length>0)             str = str + "," + obj.options[i].value;         else             str = obj.options[i].value;     }          alert(str);}</script> </head><body><div class="searchDiv mcenter" style="width:400px;">  <form name="form1" method="post" id="form1">        <table style="width:395px;margin:10px 0;" align="center" class="tblresult">   <tr>   <th colspan="3" style="font-size:14px;text-align: center">新增人員</th>   </tr>   <tr>   <td>   <table class="noborder">   <tr>   <th>已有人員</th>   </tr>   <tr><td>    <select id="fb_list" name="seled" multiple="true" style="width:160px;height:200px;">     <option value="1">張三</option>    </select>    </td></tr>    </table>   </td>   <td>    <table class="noborder"><tr><td>    <input id="add" type="button" value=">>" style="width:30px;"/></td></tr>    <tr><td>    <input id="delete" type="button" value="<<" style="width:30px;"/>    </td></tr></table>   </td>   <td>   <table class="noborder">   <tr>   <th>備用人員</th>   </tr>   <tr><td>    <select id="select_list" name="unseled" multiple="true" style="width:160px;height:200px;">     <option value="4">李四</option>     <option value="5">王五</option>    </select>    </td></tr>    </table>   </td>   </tr>            <tr>                <td colspan="3" style="text-align:center;height:35px;">    <input type="button" value="儲存" class="btn1" onclick="sel();"/>    <input type="button" value="取消" onclick="javascript:doClose();" class="btn1"/>    </td>            </tr>          </table>          </form> </div></body></html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.