基于jquery實(shí)現(xiàn)select選擇框內(nèi)容左右移動(dòng)添加刪除代碼分享
本文實(shí)例講述了select選擇框內(nèi)容左右移動(dòng)添加刪除。分享給大家供大家參考。具體如下:
select選擇框內(nèi)容左右移動(dòng)添加刪除代碼基于jquery-1.8.3.min.js實(shí)現(xiàn),簡(jiǎn)單實(shí)用,選中選項(xiàng)內(nèi)容,點(diǎn)擊移動(dòng)按鈕可進(jìn)行內(nèi)容左右移動(dòng),雙擊option內(nèi)容也可左右移動(dòng),支持單選移動(dòng)、多選移動(dòng)和一鍵全部移動(dòng)!
運(yùn)行效果圖: ----------------------查看效果-----------------------

小提示:瀏覽器中如果不能正常運(yùn)行,可以嘗試切換瀏覽模式。
為大家分享的代碼如下
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>select選擇框內(nèi)容左右移動(dòng)添加刪除代碼</title>
<style type="text/css">
*{margin:0;padding:0;list-style-type:none;outline:none;}
a,img{border:0;}
body{font:12px/normal "microsoft yahei";}
.selectbox{width:500px;height:220px;margin:100px auto;}
.selectbox div{float:left;}
.selectbox .select-bar{padding:0 20px;}
.selectbox .select-bar select{width:150px;height:200px;border:1px #A0A0A4 solid;padding:4px;font-size:14px;font-family:"microsoft yahei";}
.btn-bar{}
.btn-bar p{margin-top:16px;}
.btn-bar p .btn{width:50px;height:30px;cursor:pointer;font-family:simsun;font-size:14px;}
</style>
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
$(function(){
//移到右邊
$('#add').click(function(){
//先判斷是否有選中
if(!$("#select1 option").is(":selected")){
alert("請(qǐng)選擇需要移動(dòng)的選項(xiàng)")
}
//獲取選中的選項(xiàng),刪除并追加給對(duì)方
else{
$('#select1 option:selected').appendTo('#select2');
}
});
//移到左邊
$('#remove').click(function(){
//先判斷是否有選中
if(!$("#select2 option").is(":selected")){
alert("請(qǐng)選擇需要移動(dòng)的選項(xiàng)")
}
else{
$('#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="selectbox">
<div class="select-bar">
<select multiple="multiple" id="select1">
<option value="超級(jí)管理員">超級(jí)管理員</option>
<option value="普通管理員">普通管理員</option>
<option value="信息發(fā)布員">信息發(fā)布員</option>
<option value="財(cái)務(wù)管理員">財(cái)務(wù)管理員</option>
<option value="產(chǎn)品管理員">產(chǎn)品管理員</option>
<option value="資源管理員">資源管理員</option>
<option value="系統(tǒng)管理員">系統(tǒng)管理員</option>
<option value="超級(jí)管理員">超級(jí)管理員</option>
<option value="普通管理員">普通管理員</option>
<option value="信息發(fā)布員">信息發(fā)布員</option>
<option value="財(cái)務(wù)管理員">財(cái)務(wù)管理員</option>
<option value="產(chǎn)品管理員">產(chǎn)品管理員</option>
<option value="資源管理員">資源管理員</option>
<option value="A5源碼">A5源碼</option>
</select>
</div>
<div class="btn-bar">
<p><span id="add"><input type="button" class="btn" value=">" title="移動(dòng)選擇項(xiàng)到右側(cè)"/></span></p>
<p><span id="add_all"><input type="button" class="btn" value=">>" title="全部移到右側(cè)"/></span></p>
<p><span id="remove"><input type="button" class="btn" value="<" title="移動(dòng)選擇項(xiàng)到左側(cè)"/></span></p>
<p><span id="remove_all"><input type="button" class="btn" value="<<" title="全部移到左側(cè)"/></span></p>
</div>
<div class="select-bar">
<select multiple="multiple" id="select2"></select>
</div>
</div>
<div style="text-align:center;">
</div>
</body>
</html>
以上就是為大家分享的select選擇框內(nèi)容左右移動(dòng)添加刪除代碼,希望大家可以喜歡。
- Chosen 基于jquery的選擇框插件使用方法
- jQuery實(shí)現(xiàn)選中彈出窗口選擇框內(nèi)容后賦值給文本框的方法
- 基于JQuery的Select選擇框的華麗變身
- 基于jQuery下拉選擇框插件支持單選多選功能代碼
- jquery通過select列表選擇框?qū)Ρ砀駭?shù)據(jù)進(jìn)行過濾示例
- jquery實(shí)現(xiàn)select選擇框內(nèi)容左右移動(dòng)代碼分享
- 各種選擇框jQuery的選中方法(實(shí)例講解)
- Jquery多選下拉列表插件jquery multiselect功能介紹及使用
- 用jquery實(shí)現(xiàn)下拉菜單效果的代碼
- 用jquery實(shí)現(xiàn)的一個(gè)超級(jí)簡(jiǎn)單的下拉菜單
- jQuery模擬12306城市選擇框功能簡(jiǎn)單實(shí)現(xiàn)方法示例
相關(guān)文章
深入理解jquery自定義動(dòng)畫animate()
下面小編就為大家?guī)硪黄钊肜斫鈐query自定義動(dòng)畫animate()。小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-05-05
jQuery通過ajax方法獲取json數(shù)據(jù)不執(zhí)行success的原因及解決方法
這篇文章主要介紹了jQuery通過ajax方法獲取json數(shù)據(jù)不執(zhí)行success的原因及解決方法的相關(guān)資料,需要的朋友可以參考下2016-10-10
jQuery slider Content(左右控制移動(dòng))
jQuery slider Content(左右控制移動(dòng))實(shí)現(xiàn)代碼,大家可以參考下。2009-09-09
jquery動(dòng)態(tài)改變form屬性提交表單
在js中動(dòng)態(tài)改變form的屬性,滿足不同條件的form提交需求,下面有個(gè)不錯(cuò)的示例,大家可以參考下2014-06-06
jquery與prototype框架的詳細(xì)對(duì)比
這篇文章主要是對(duì)jquery與prototype框架進(jìn)行了詳細(xì)的對(duì)比介紹,需要的朋友可以過來參考下,希望對(duì)大家有所幫助2013-11-11
基于JQuery實(shí)現(xiàn)的跑馬燈效果(文字無縫向上翻動(dòng))
本篇文章分享了如何實(shí)現(xiàn)文字無縫向上翻動(dòng)效果的示例代碼。代碼清晰明了,可直接下載使用。有興趣的朋友可以看下2016-12-12
基于jQuery.validate及Bootstrap的tooltip開發(fā)氣泡樣式的表單校驗(yàn)組件思路詳解
這篇文章主要介紹了基于jQuery.validate及Bootstrap的tooltip開發(fā)氣泡樣式的表單校驗(yàn)組件的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友一起看下吧2016-07-07

