欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Jquery實(shí)現(xiàn)select multiple左右添加和刪除功能的簡(jiǎn)單實(shí)例

 更新時(shí)間:2016年05月26日 11:38:16   投稿:jingxian  
下面小編就為大家?guī)?lái)一篇Jquery實(shí)現(xiàn)select multiple左右添加和刪除功能的簡(jiǎn)單實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

項(xiàng)目要實(shí)現(xiàn)這樣的一個(gè)功能(如下圖所示):選擇左邊下拉列表框中的選項(xiàng),點(diǎn)擊添加按鈕,把選擇的選項(xiàng)移動(dòng)到右邊的下拉列表框中,同樣的選擇右邊的選項(xiàng),點(diǎn)擊刪除按鈕,即把選擇的選項(xiàng)移動(dòng)到左邊的下拉列表框中.相信用js很多朋友都寫(xiě)過(guò),下面是我用jQuery來(lái)實(shí)現(xiàn)這樣的功能的。

具體代碼如下:

<center>
 <table>
 <tr align="center">
  <td colspan="3">
  選擇
  </td>
 </tr>
 <tr>
  <td>
  <select id="fb_list" name="fb_list" multiple="multiple"
  size="8" style="width: 300px; height:200px;">
  </select>
  </td>
  <td>
  <input type="button" id="selectup" name="selectup" value="上移∧" />
  <br />
  <input type="button" id="add" name="add" value="添加>>" />
  <br />
  <input type="button" id="delete" name="delete" value="<<移除" />
  <br />  
  <input type="button" id="selectdown" name="selectdown" value="下移∨" />
  </td>
  <td>
  <select id="select_list" name="select_list" multiple="multiple"
  size="8" style="width: 300px; height:200px;">
  </select>
  </td>
 </tr>
 </table>
 </center>

$(function(){
 $.post('testAction!excute.action',null,function(data){
  // var to_data = eval('('+data+')');
 var array = eval(data);
  var obj = document.getElementById("fb_list");
  var value = "";
  for(var i=0;i<array.length;i++){
   value = array[i].id + "/" + array[i].name + "/" + array[i].tel;
   obj.options[i] = new Option(value,value);
   //obj.add(newOption);
   }
  })
});

//向右移動(dòng)
$(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("請(qǐng)選擇要添加的分包!");
       }
   })
})
//向左移動(dòng)
$(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("請(qǐng)選擇要?jiǎng)h除的分包!");
           }
     })
})

//向上移動(dòng)
$(function(){
 $("#selectup").click(function(){
 if($("select[name='fb_list'] option:selected").length > 0){
 $("select[name='fb_list'] option:selected").each(function(){
 $(this).prev().before($(this));
 })
 }else{
 alert("請(qǐng)選擇要移動(dòng)的數(shù)據(jù)!");
 }
 })
})
//向下移動(dòng)
$(function(){
 $("#selectdown").click(function(){
 if($("select[name='fb_list'] option:selected").length > 0){
 $("select[name='fb_list'] option:selected").each(function(){
 //$(this).next().after($(this));
 $(this).insertAfter($(this).next());
 })
 }else{
 alert("請(qǐng)選擇要移動(dòng)的數(shù)據(jù)!");
 }
 })
})

以上這篇Jquery實(shí)現(xiàn)select multiple左右添加和刪除功能的簡(jiǎn)單實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論