基于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通過(guò)select列表選擇框?qū)Ρ砀駭?shù)據(jù)進(jìn)行過(guò)濾示例
- 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實(shí)現(xiàn)仿51job城市選擇功能實(shí)例代碼
這篇文章主要介紹了基于jQuery實(shí)現(xiàn)仿51job城市選擇功能實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下2016-03-03jquery簡(jiǎn)單實(shí)現(xiàn)鼠標(biāo)經(jīng)過(guò)導(dǎo)航條改變背景圖
鼠標(biāo)經(jīng)過(guò)導(dǎo)航條改變背景圖的效果很是好看,下面為大家介紹下使用jquery是如何實(shí)現(xiàn)的,感興趣的朋友可以參考下2013-12-12jQuery插件HighCharts實(shí)現(xiàn)的2D對(duì)數(shù)餅圖效果示例【附demo源碼下載】
這篇文章主要介紹了jQuery插件HighCharts實(shí)現(xiàn)的2D對(duì)數(shù)餅圖效果,結(jié)合實(shí)例形式分析了jQuery圖形插件HighCharts繪制2D對(duì)數(shù)餅圖的具體實(shí)現(xiàn)步驟與相關(guān)操作技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2017-03-03jQuery移除或禁用html元素點(diǎn)擊事件常用方法小結(jié)
這篇文章主要介紹了jQuery移除或禁用html元素點(diǎn)擊事件常用方法,結(jié)合實(shí)例形式總結(jié)分析了jQuery針對(duì)onclick事件的禁用與屏蔽技巧,需要的朋友可以參考下2017-02-02『jQuery』名稱(chēng)沖突使用noConflict方法解決
jQuery 使用 $ 符號(hào)作為 jQuery 的簡(jiǎn)介方式。某些其他 JavaScript 庫(kù)中的函數(shù)(比如 Prototype)同樣使用 $ 符號(hào),這樣就會(huì)發(fā)生名稱(chēng)沖突,使用名為 noConflict() 的方法來(lái)解決該問(wèn)題2013-04-04jquery實(shí)現(xiàn)控制表格行高亮實(shí)例
jquery實(shí)現(xiàn)控制表格行高亮實(shí)例,需要的朋友可以參考一下2013-06-06