jQuery下拉框的簡(jiǎn)單應(yīng)用
先看看效果圖:

大家肯定都見(jiàn)過(guò)類(lèi)似效果的網(wǎng)頁(yè),怎么實(shí)現(xiàn)的呢,代碼很簡(jiǎn)單:
<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>
<!-- 引入jQuery -->
<script src="jquery-2.1.0.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
//移到右邊
$('#add').click(function() {
//獲取選中的選項(xiàng),刪除并追加給對(duì)方
$('#select1 option:selected').appendTo('#select2');
});
//移到左邊
$('#remove').click(function() {
$('#select2 option:selected').appendTo('#select1');
});
//全部移到右邊
$('#add_all').click(function() {
//獲取全部的選項(xiàng),刪除并追加給對(duì)方
$('#select1 option').appendTo('#select2');
});
//全部移到左邊
$('#remove_all').click(function() {
$('#select2 option').appendTo('#select1');
});
//雙擊選項(xiàng)
$('#select1').dblclick(function(){ //綁定雙擊事件
//獲取全部的選項(xiàng),刪除并追加給對(duì)方
$("option:selected",this).appendTo('#select2'); //追加給對(duì)方
});
//雙擊選項(xiàng)
$('#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">曹操</option>
<option value="2">曹昂</option>
<option value="3">曹丕</option>
<option value="4">曹彰</option>
<option value="5">曹植</option>
<option value="6">曹熊</option>
<option value="7">曹仁</option>
<option value="8">曹洪</option>
<option value="9">曹休</option>
<option value="10">曹真</option>
<option value="11">曹爽</option>
</select>
<div>
<span id="add" >選中添加到右邊>></span>
<span id="add_all" >全部添加到右邊>></span>
</div>
</div>
<div class="centent">
<select multiple="multiple" id="select2" style="width: 100px;height:160px;">
<option value="12">曹芳</option>
</select>
<div>
<span id="remove"><<選中刪除到左邊</span>
<span id="remove_all"><<全部刪除到左邊</span>
</div>
</div>
</body>
</html>
代碼實(shí)現(xiàn)的功能:
1)、將選中的選項(xiàng)添加給對(duì)方
2)、將全部選項(xiàng)添加給對(duì)方
3)、雙擊某個(gè)選項(xiàng)將其添加給對(duì)方
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- JQuery下拉框應(yīng)用示例介紹
- jQuery+easyui中的combobox實(shí)現(xiàn)下拉框特效
- jQuery實(shí)現(xiàn)鼠標(biāo)經(jīng)過(guò)時(shí)出現(xiàn)隱藏層文字鏈接的方法
- jquery實(shí)現(xiàn)通用版鼠標(biāo)經(jīng)過(guò)淡入淡出效果
- jQuery實(shí)現(xiàn)table隔行換色和鼠標(biāo)經(jīng)過(guò)變色的兩種方法
- jQuery 鼠標(biāo)經(jīng)過(guò)(hover)事件的延時(shí)處理示例
- jQuery實(shí)現(xiàn)鼠標(biāo)經(jīng)過(guò)圖片預(yù)覽大圖效果
- Jquery利用mouseenter和mouseleave實(shí)現(xiàn)鼠標(biāo)經(jīng)過(guò)彈出層且可以點(diǎn)擊
- Jquery中國(guó)地圖熱點(diǎn)效果-鼠標(biāo)經(jīng)過(guò)彈出提示層信息的簡(jiǎn)單實(shí)例
- jquery簡(jiǎn)單實(shí)現(xiàn)鼠標(biāo)經(jīng)過(guò)導(dǎo)航條改變背景圖
- jQuery實(shí)現(xiàn)鼠標(biāo)經(jīng)過(guò)購(gòu)物車(chē)出現(xiàn)下拉框代碼(推薦)
相關(guān)文章
jQuery動(dòng)態(tài)添加<input type="file">
有時(shí)候需要在頁(yè)面上允許用戶上傳多個(gè)文件,個(gè)數(shù)由用戶自己決定,個(gè)數(shù)多了也可以刪除,使用jQuery可以很簡(jiǎn)單的實(shí)現(xiàn)這個(gè)功能2016-04-04
zTree節(jié)點(diǎn)文字過(guò)多的處理方法
這篇文章主要為大家詳細(xì)介紹了zTree節(jié)點(diǎn)文字過(guò)多的處理方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-11-11
jquery+css實(shí)現(xiàn)的紅色線條橫向二級(jí)菜單效果
這篇文章主要介紹了jquery+css實(shí)現(xiàn)的紅色線條橫向二級(jí)菜單效果,界面美觀大方,簡(jiǎn)潔實(shí)用,通過(guò)jquery遍歷及切換頁(yè)面元素實(shí)現(xiàn)這一功能,需要的朋友可以參考下2015-08-08
jquery.pagination.js分頁(yè)使用教程
這篇文章主要為大家詳細(xì)介紹了jquery.pagination.js分頁(yè)使用教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-10-10
jQuery插件bgStretcher.js實(shí)現(xiàn)全屏背景特效
可以自動(dòng)動(dòng)態(tài)更換網(wǎng)頁(yè)背景圖片的jQuery插件bgstretcher.js,sharejs.com推薦的這個(gè)插件,可以自定義多種方式讓網(wǎng)頁(yè)背景自動(dòng)切換,效果流暢,非常難得,調(diào)用代碼也非常簡(jiǎn)單。2015-06-06
jQuery實(shí)現(xiàn)王者榮耀手風(fēng)琴效果
這篇文章主要介紹了jQuery實(shí)現(xiàn)王者榮耀手風(fēng)琴效果的代碼內(nèi)容,需要的朋友們可以學(xué)習(xí)下。2020-01-01
jquery簡(jiǎn)單圖片切換顯示效果實(shí)現(xiàn)方法
這篇文章主要介紹了jquery簡(jiǎn)單圖片切換顯示效果實(shí)現(xiàn)方法,可以實(shí)現(xiàn)簡(jiǎn)單的圖片切換功能,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-01-01

