`

JQ 下拉框左右选择

 
阅读更多
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
* {
	margin: 0;
	padding: 0;
}
div.centent {
	float: left;
	text-align: center;
	margin: 10px;
}
span {
	display: block;
	margin: 2px 2px;
	padding: 4px 10px;
	background: #898989;
	cursor: pointer;
	font-size: 12px;
	color: white;
}
</style>
<script src="js/jquery-1.10.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
	//移到右边
	$('#add').click(function() {
		//获取选中的选项,删除并追加给对方
		$('#select1 option:selected').appendTo('#select2');
	});
	//移到左边
	$('#remove').click(function() {
		$('#select2 option:selected').appendTo('#select1');
	});
	//全部移到右边
	$('#add_all').click(function() {
		//获取全部的选项,删除并追加给对方
		$('#select1 option').appendTo('#select2');
	});
	//全部移到左边
	$('#remove_all').click(function() {
		$('#select2 option').appendTo('#select1');
	});
	//双击选项
	$('#select1').dblclick(function(){ //绑定双击事件
		//获取全部的选项,删除并追加给对方
		$("option:selected",this).appendTo('#select2'); //追加给对方
	});
	//双击选项
	$('#select2').dblclick(function(){
		$("option:selected",this).appendTo('#select1');
	});
});
</script>
</head>
<body>
<div class="centent">
    <select multiple="multiple" id="select1" style="width:100px;height:160px;">
        <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>
    <div> <span id="add" >选中添加到右边&gt;&gt;</span> <span id="add_all" >全部添加到右边&gt;&gt;</span> </div>
</div>
<div class="centent">
    <select multiple="multiple" id="select2" style="width: 100px;height:160px;">
        <option value="8">选项8</option>
    </select>
    <div> <span id="remove">&lt;&lt;选中删除到左边</span> <span id="remove_all">&lt;&lt;全部删除到左边</span> </div>
</div>
</body>
</html>

效果图:

 

 

 

  • 大小: 37.4 KB
分享到:
评论

相关推荐

    jquery实现下拉框左右选择功能

    1、说明 本文demo实现下拉框左右选择 2、代码 &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;... ...style type

    select互选效果

    当用户在其中一个下拉框中选择一个选项时,JavaScript会检查这个选项是否已经在另一个下拉框中,如果不在,就将其添加;如果已经在,就将其移除。这种操作可以通过遍历每个下拉框的`&lt;option&gt;`元素并比较它们的值来...

    jQuery实现下拉框左右移动(全部移动,已选移动)

    在标题中提到的“jQuery实现下拉框左右移动(全部移动,已选移动)”中,所涉及的知识点包括了: 1. jQuery选择器的使用:通过id选择器(例如$("#select1"))选取页面上的下拉框元素,以及使用伪选择器(例如$("#...

    jquery下拉多级树选择插件(支持左右移动,以及模糊搜索功能).zip

    本项目聚焦于一个基于jQuery的下拉多级树选择插件,该插件具备左右移动功能和模糊搜索特性,极大地提高了用户在下拉列表中的操作效率。 首先,我们来深入理解这个插件的核心特点: 1. **多级树结构**:此插件能够...

    jQuery实现可移动选项的左右下拉列表示例

    本文实例讲述了jQuery实现可移动选项的左右下拉列表。分享给大家供大家参考,具体如下: 运行效果图如下: 完整代码如下: &lt;html&gt; &lt;head&gt; &lt;meta http-equiv=Content-Type content=text/html; ...

    day04-jq.zip

    最后,"05-下拉列表左右选择"是一种常见的选项交换功能,用户可以在两个下拉列表之间移动选项。这需要监听下拉列表的`change`事件,然后使用`.append()`和`.remove()`方法将选项在两个列表之间转移。同时,确保正确...

Global site tag (gtag.js) - Google Analytics