2个下拉列表中的元素相互移动

案例完成代码与解析

<!DOCTYPE html>
<html>
	<head>
		<script type="text/javascript" src="js/jquery-1.11.2.js"></script>
		<meta charset="UTF-8">
		<style type="text/css">
			select {
				height: 140px;
				border: #000 1px solid;
			}
		</style>
	</head>
	<body>
		<select multiple="multiple" id="select1">
			<option value="看书">看书</option>
			<option value="旅游">旅游</option>
			<option value="运动">运动</option>
			<option value="购物">购物</option>
		</select>
		<input type="button" value="<==" id="b4" onclick="b4()">
		<input type="button" value="<=" id="b3" onclick="b3()">
		<input type="button" value="=>" id="b1" onclick="b1()">
		<input type="button" value="==>" id="b2" onclick="b2()">
		<select multiple="multiple" id="select2">
			<option value="游戏">游戏</option>	
		</select>
		<script>
//现在做一号下拉列表全部向二号下拉列表移动
			function b2 () {
                //被动节点追加,将一号下拉列表的全部元素追加到二号下拉列表
				$('#select1 option').appendTo ('#select2')
			}
//现在做二号下拉列表全部向一号下拉列表移动
			function b4 () {
                //被动节点追加,将二号下拉列表的全部元素追加到一号下拉列表
				$('#select2 option').appendTo ('#select1')
			}
//现在做二号下拉列表选中的元素向一号下拉列表移动
			function b3 () {
                 //被动节点追加,将二号下拉列表的选中的元素追加到一号下拉列表
				$('#select2 option:selected').appendTo('#select1')
			}
//现在做一号下拉列表选中的元素向二号下拉列表移动
			function b1 () {、
                 //被动节点追加,将一号下拉列表的选中的元素追加到二号下拉列表
				$('#select1 option:selected').appendTo('#select2')
			}
		</script>
	</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值