Multi-selectable drop-down list box based on jquery_jquery
WBOY
Release: 2016-05-16 17:51:34
Original
1444 people have browsed it
Colleagues found bugs in the drop-down list box that they found on the Internet, such as incorrect positioning and slow loading. Anyway, the implementation of the multi-select drop-down list box is very simple. Instead of looking at the messy structure of the code, it is better to re-implement it yourself.
'); var $ul = $list.find("ul"); //Loading json data var listArr = op.data.split("|"); var jsonData; for (var i = 0; i < listArr.length; i ) { jsonData = eval("(" listArr[i] ")"); $ul.append('
'); } //Load the check option var seledArr; if (op.selected.length > 0 ) { seledArr = selected.split(","); } else { seledArr = $hf.val().split(","); } $.each(seledArr, function (index) { $("li input[value='" seledArr[index] "']", $ul).attr("checked", "checked"); var vArr = new Array(); $("input[class!='selectAll']:checked", $ul).each(function (index) { vArr[index] = $( this).next().text(); }); $this.val(vArr.join(",")); }); //Select all or all Uncheck $("li:first input", $ul).click(function () { if ($(this).attr("checked")) { $("li input ", $ul).attr("checked", "checked"); } else { $("li input", $ul).removeAttr("checked"); } }); //When clicking other check boxes, update the hidden control value and the value of the text box $("input", $ul).click(function () { var kArr = new Array(); var vArr = new Array(); $("input[class!='selectAll']:checked", $ul).each(function (index) { kArr[index] = $(this).val(); vArr[index] = $(this).next().text(); }); $hf.val (kArr.join(",")); $this.val(vArr.join(",")); }); }); } }) ; })(jQuery); $(document).ready(function () { $("#txtTest").MultDropList({ data: $("#hfddlList").val( ) }); });
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn