温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

jquery 两个select控件左右移动并上下移动

发布时间:2020-06-28 08:16:55 来源:网络 阅读:2750 作者:wanfeng1979 栏目:web开发
<script type="text/javascript" src="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 style="height:300px!important; width:150px;">
        <?php foreach($arrFieldName as $key=>$val){?>
        <option val="<?php echo $key;?>"><?php echo $val;?></option>
        <?php }?>
      </select></td>
    <td style="width:100px; text-align:center;"><input type="button" id="buttonToRight"  value="&raquo;"  style="background:none; width:50px;" />
      <br/>
      <br/>
      <input type="button" value="&laquo;" id="buttonToLeft"  style="background:none; width:50px;" />
      <br/>
      <br/>
      <input type="button" value="&uarr;" id="buttonToUp" style="background:none; width:50px;" />
      <br/>
      <br/>    
      <input type="button" value="&darr;"  id="buttonToDown" style="background:none; width:50px;" />
      </td>
    <td><select name="selectTwo" size="5" multiple style="height:300px!important; width:150px;">          
      </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();

jquery 两个select控件左右移动并上下移动
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI