天易23----jquery实现下拉菜单的左右移动


功能说明:该实例包括选中一项或多项点击选中右移按钮将选中的选项右移到右边的菜单,也可选择全部右移按钮将左菜单的所有选项全部右移右边菜单,或双击左菜单中的选项右移到右下拉菜单,最后点击“提交”按钮查看右菜单选项中的所选选项,右菜单操作和左菜单的操作一样,具体操作详见下边示例!

一:总体实现效果图:
1):

2):当点击提交按钮时,会弹出对话框查看右菜单中的选项

二:示例代码:

1)elevenjsp.js代码:

$(document).ready(function(){
	
	$('#add').click(function(){
		
		$('#select1 option:selected').appendTo('#select2');
		
	});
	$('#add_all').click(function(){
		
		$('#select1 option').appendTo('#select2');
	});
	
	$('#remove').click(function(){
		
		$('#select2 option:selected').appendTo('#select1');
		
	});
	
	$('#remove_all').click(function(){
		
		$('#select2 option').appendTo('#select1');
		
	});
	//双击选项的时候实现右移,双击事件:dblclick
	$('#select1').dblclick(function(){
		
		$('#select1 option:selected').appendTo('#select2');
	});
	//双击选项的时候实现左移,双击事件:dblclick
	$('#select2').dblclick(function(){
		
		$('#select2 option:selected').appendTo('#select1');
	});
	
	//点击提交按钮查看所选内容
	  $('#send').click(function(){
	  
	  	var str="你选择的是:";
	  	$('#select2 option').each(function(){
			
			str+=$(this).val()+",";//接收显示所选复选框的内容
		});
		
	  	alert(str);
	  });
	
});

2)页面代码:


<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title></title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<script type="text/javascript" src="<%=basePath %>js/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="<%=basePath %>js/elevenjsp.js"></script>
<style type="text/css">
*{padding:0;margin:0;}
body {padding:100px;font-size:12px;font-family:"宋体";}
select{width:100px;height:170px;padding:5px;}
.content{float:left;text-align:center;margin-right:10px;}
span{display:block;width:90px;cursor:pointer;background:#eee;border:1px solid #ccc;padding:5px 0;margin:5px 0;}
</style> 
</head>

<body>
<div class="content">
<select multiple="multiple" id="select1">
<option value="1" >选项1</option>
<option value="2">选项2</option>
<option value="3">选项3</option>
<option value="4">选项4</option>
<option value="5">选项5</option>
<option value="6">选项6</option>
<option value="7">选项7</option>
</select>
<span id="add">选中右移>></span>
<span id="add_all">全部右移>></span>
</div>
<div class="content">
<select multiple="multiple" id="select2">
</select>
<span id="remove">选中左移>></span>
<span id="remove_all">全部左移>></span>
<input type="button" id="send" value="提    交"/>
</div>
</body>
</html>




评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值