jQuery实现双向选择列表框

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>双向选择列表框</title>
 <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
  </head>
  <script type="text/javascript">
  //添加一些测试内容
  $(function(){
   for(var i=1;i<10;i++){
    $("#leftBox").append("<option value='"+i+"'>192.168.0.2"+i+"</option>");
    $("#rightBox").append("<option value='"+i+9+"'>221.11.48.16"+i+"</option>");
   }
  });
 </script>
 <body>
  <form name="form1" action="" method="">
  <div>
   <table align="center" width="50%">
    <tr>
     <td width="40%">
      <select id="leftBox" size="15" style="width:90%;" multiple="multiple">
      </select>
     </td>
     <td width="20%" align="center">
      <input id="allRight" type="button" value="  >>  ">
      <p><br>
      <input id="allLeft" type="button" value="  <<  ">
     </td>
     <td width="40%">
      <select id="rightBox" size="15" style="width:90%;" multiple="multiple"></select>
     </td>
    </tr>
   </table>
  </div>
  <br>
  <div align="center">
   <input id="btnLeft" type="button" value="左侧保存">
   &nbsp;&nbsp;&nbsp;
   <input id="btnRight" type="button" value="右侧保存">
  </div>
  </form>
 </body>
 <script type="text/javascript">
 $(function(){
 //由左移到右
 $("#leftBox").change(function(){
  var lbox = $("#leftBox option:selected");
  $(lbox).each(function(){
   $(lbox).remove();
   $("#rightBox").append(lbox);
  });
  $("#rightBox").attr("selectedIndex",-1);
 });
 //由右移到左
 $("#rightBox").change(function(){
  var rbox = $("#rightBox option:selected");
  $(rbox).each(function(){
   rbox.remove();
   $("#leftBox").append(rbox);
  });
  $("#leftBox").attr("selectedIndex",-1);
 });
 //全部移动到右侧
 $("#allRight").click(function(){
  $("#leftBox option").appendTo("#rightBox");
 });
 //全部移动到左侧
 $("#allLeft").click(function(){
  $("#rightBox option").appendTo("#leftBox");
 });
 //左侧保存
 $("#btnLeft").click(function(){
  var larr = new Array();
  $("#leftBox option").each(function(){
   larr.push($(this).val());
  });
  if(confirm("确认修改权限设置?")==true){
   $.ajax({
    url:'updateJobMenu.action',
    type:'POST',
    data:{'strValue':larr.toString()},
    error:function(){
     alert("数据加载出现异常,请重试!");
    },
    success:function(){
     alert("权限修改成功!");
    }
   }); 
  }
 });
 //右侧保存
 $("#btnRight").click(function(){
  var rarr = new Array();
  $("#rightBox option").each(function(){
   rarr.push($(this).val());
  });
  if(confirm("确认修改权限设置?")==true){
   $.ajax({
    url:'updateJobMenu.action',
    type:'POST',
    data:{'strValue':rarr.toString()},
    error:function(){
     alert("数据加载出现异常,请重试!");
    },
    success:function(){
     alert("权限修改成功!");
    }
   }); 
  }
 });
});
 </script>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值