亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

jquery 兩個select控件左右移動并上下移動

標簽:
JQuery

         <script type="text/javascript" class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="jquery-1.3.2.min.js" />
<table boder='1'>
  <tr>
    <th>待选字段</th>
    <td></td>
    <th>报表导出字段</th>
  </tr>
  <tr>
    <td><select name="selectOne" size="5" multiple >
        <?php foreach($arrFieldName as $key=>$val){?>
        <option val="<?php echo $key;?>"><?php echo $val;?></option>
        <?php }?>
      </select></td>
     <td ><input  type="button" id="buttonToRight"  value="&raquo;"    />
      <br/>
      <br/>
      <input type="button" value="&laquo;" id="buttonToLeft"   />
      <br/>
      <br/>
      <input type="button" value="&uarr;" id="buttonToUp"  />
      <br/>
      <br/>    
      <input type="button" value="&darr;"  id="buttonToDown"  />
      </td>
    <td><select name="selectTwo" size="5" multiple >          
      </select></td>
  </tr>
  <tr>
    <td ></td>
    <td><a class="button"><span class="icon icon-output">确认导出</span></a></td>
    <td></td>
  </tr>
</table>
<script type="text/javascript">
$(function(){
    $('#buttonToRight').click(function(){
        if($("select[name=selectOne] option:selected").length>0){             
            $("select[name=selectOne] option:selected").each(function(i){                           
                 $("select[name=selectTwo]").append("<option value='"+$(this).val()+"'>"+$(this).text()+"</option"); 
//从左移到右边
                 $(this).remove();  //左边的删除
            });
        }
    });
       
    $('#buttonToLeft').click(function(){
         if($("select[name=selectTwo] option:selected").length>0){             
             $("select[name=selectTwo] option:selected").each(function(i){
                  $("select[name=selectOne]").append("<option value='"+$(this).val()+"'>"+$(this).text()+"</option");
                  $(this).remove();
             });
         }
        });
    $('#buttonToUp').click(function(){       
        if($("select[name=selectTwo] option:selected").length>0){             
            $("select[name=selectTwo] option:selected").each(function(i){
                $(this).prev().before($(this));  //上移
            });
         }
    });
    $('#buttonToDown').click(function(){     
        if($("select[name=selectTwo] option:selected").length>0){             
            $("select[name=selectTwo] option:selected").each(function(i){
                $(this).next().after($(this)); 
                $(this).insertAfter($(this).next());  //下移
            });
         }
    });

});
</script>
 

 获取select 选中的 text :

   $("#ddlRegType").find("option:selected").text();

 

 获取select选中的 value:

   $("#ddlRegType ").val();

 

获取select选中的索引:

     $("#ddlRegType ").get(0).selectedIndex;

 

 设置select 选中的索引:

     $("#ddlRegType ").get(0).selectedIndex=index;//index为索引值


 设置select 选中的value:

  $("#ddlRegType ").get(0).value = value;

 

//select option的数量

("#ddlRegType option").length;

 

$("#select_id").append("<option value='Value'>Text</option>");  //添加一项option

 $("#select_id").prepend("<option value='0'>请选择</option>"); //在前面插入一项option

 $("#select_id option:last").remove(); //删除索引值最大的Option

 $("#select_id option[index='0']").remove();//删除索引值为0的Option

 $("#select_id option[value='3']").remove(); //删除值为3的Option

 $("#select_id option[text='4']").remove(); //删除TEXT值为4的Option

 

清空 Select:

$("#ddlRegType ").empty();

點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
移動開發工程師
手記
粉絲
18
獲贊與收藏
136

關注作者,訂閱最新文章

閱讀免費教程

  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消