這次帶給大家JS怎樣實現左右兩側選單添加與移除,JS實現左右兩側選單添加與移除的注意事項有哪些,下面就是實戰案例,一起來看一下。
效果圖:
JS程式碼
function toRight(l, r, v) { $("#" + l + " option:selected").appendTo("#" + r); $("#" + l + " option:selected").remove(); var str = $("#" + l + " option").map(function () { return $(this).val(); }).get().join(", ") $("#" + v).val(str); } function allToRight(l, r, v) { $("#" + l + " option").appendTo("#" + r); $("#" + l + " option").remove(); var str = $("#" + l + " option").map(function () { return $(this).val(); }).get().join(", ") $("#" + v).val(str); } function toLeft(l, r, v) { $("#" + r + " option:selected").appendTo("#" + l); $("#" + r + " option:selected").remove(); var str = $("#" + l + " option").map(function () { return $(this).val(); }).get().join(", ") $("#" + v).val(str); } function allToLeft(l, r, v) { $("#" + r + " option").appendTo("#" + l); $("#" + r + " option").remove(); var str = $("#" + l + " option").map(function () { return $(this).val(); }).get().join(", ") $("#" + v).val(str); }
html程式碼
<p class="easyui-layout" data-options="fit:true"> <p data-options="region:'west',split:false" style="width:40%;padding:0px"> <h3 style="padding:5px; border-bottom:1px solid #DDDDDD;">::已授权权限::</h3> <p data-options="region:'center'" style="padding:3px; height:215px;" border="false"> <select multiple="multiple" id="menuFunc" style="width:100%;height:100%"> </select> <input type="hidden" name="func" id="func" value="" /> </p> </p> <p data-options="region:'east'" style="width:40%;padding:0px"> <h3 style="padding:5px;border-bottom:1px solid #DDDDDD;">::未授权权限::</h3> <p data-options="region:'center'" style="padding:3px; height:215px;" border="false"> <select multiple="multiple" id="menuFuncBase" style="width:100%;height:100%"> </select> </p> </p> <p data-options="region:'center'" style="padding:40px; width: 197px; height:230px;line-height:40px; text-align:center;"> <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="button button-primary button-rounded button-small" onclick="toLeft('menuFunc','menuFuncBase','func')" > < </a><br /> <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="button button-primary button-rounded button-small" onclick="allToLeft('menuFunc','menuFuncBase','func')" ><<</a><br /> <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="button button-caution button-rounded button-small" onclick="toRight('menuFunc','menuFuncBase','func')" > > </a><br /> <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="button button-caution button-rounded button-small" onclick="allToRight('menuFunc','menuFuncBase','func')">>></a><br /> </p> </p>
相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!
推薦閱讀:
#以上是JS怎麼實現左右兩側選單添加與移除的詳細內容。更多資訊請關注PHP中文網其他相關文章!