jQuery实现两个列表框的值之间的互换:

jQuery实现两个列表框的值之间的互换:

截图如下:

代码如下:

 

<%@ 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">
<script src="http://code.jquery.com/jquery-latest.js"></script> 
<script type="text/javascript">
	$(function(){
		$("#right").click(function(){	<%--判断用户是否单击的向右按钮--%>
			var $options = $("#select option:selected");	<%--获取用户选择的列表项--%>
			var $remove = $options.remove();	<%--将列表项删除--%>
			$remove.appendTo('#select2');	<%--将删除的列表项追加到select2中--%>
		});
		
		$('#rightAll').click(function(){	<%--判断用户是否单击了全部向右移动按钮--%>
			var $options = $('#select option');	<%--获取全部的列表项--%>
			$options.appendTo('#select2');	<%--将全部的列表项追加到select2中--%>
		});
		
		$("#left").click(function(){
			var $options = $('#select2 option:selected');	<%--判断用户是否单击的向左按钮--%>
			var $remove = $options.remove();	<%--将列表项删除--%>
			$remove.appendTo('#select');	<%--将删除的列表项追加到select中--%>
		});
		
		$('#leftAll').click(function(){
			var $options = $('#select2 option');
			var $remove = $options.remove();
			$remove.appendTo('#select');
		});
		
	});
</script>
</head>

<body>
<table border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td width="125">
			<div align="center">
				<label>
					<select multiple="multiple" size="6" name="select" id="select">
						<option value="英语听说">英语听说</option>
						<option value="声乐">声乐</option>
						<option value="美术">美术</option>
						<option value="书法">书法</option>
						<option value="高数">高数</option>
						<option value="儿童文学">儿童文学</option>
					</select>
				</label>
			</div>
		</td>
		<td width="51">
			<label>
				<div align="center">
					<input type="button" name="right" id="right" value=">|"/><br/>
					<input type="button" name="rightAll" id="rightAll" value=">>"/><br/>
					<input type="button" name="left" id="leftAll" value="<<"/><br/>
					<input type="button" name="leftAll" id="left" value="|<"/>
				</div>
			</label>
		</td>
		<td width="125">
			<div align="center">
				<select multiple="multiple" size="6" name="select2" id="select2">
				
				</select>
			</div>
		</td>
	</tr>
</table>
</body>
</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

迷彩的博客

你的鼓励将是我最大的创作动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值