简体   繁体   English

如何使用jQuery multiselect同时显示组名和下拉列表项?

[英]How to display Group name also along with dropdown list items using jquery multiselect?

Hi i am using http://www.erichynds.com/jquery/jquery-ui-multiselect-widget plugin for multiselect of dropdown with option group. 嗨,我正在使用http://www.erichynds.com/jquery/jquery-ui-multiselect-widget插件对带有选项组的下拉列表进行多选。

I want to display group name also along with items. 我还要显示组名和项目。 please find the code below which i used for the same. 请找到下面我用于相同的代码。

<script type="text/javascript">
    $(document).ready(function () {
        $(".multiselect").multiselect({
            selectedList: 10,
            noneSelectedText: 'Select Options',
            header: false,
            show: ['slide', 100],
            hide: ['explode', 100], //explode,bounce
            height: 200,
            multiple: true,
            autoOpen: false,
            position: {
                my: 'center',
                my: 'top',
                at: 'center',
                at: 'bottom'
            }
        });

        var target = $('#<%=hdnftest.ClientID %>');
        var a = "";
        $(".multiselect").multiselect().bind("multiselectclick multiselectcheckall multiselectuncheckall", function (event, ui) {
            var checkedValues = $.map($(this).multiselect("getChecked"), function (input) {
                return (input.value + ':' + input.title);
            });
            target.val(
            checkedValues.length
                ? checkedValues.join(', ')
                : 'Please select a checkbox'
        );

        }).triggerHandler("multiselectclick");
        $(".multiselect").multiselect("close");

    });

      </script>

    <select class="multiselect" multiple="multiple">
         <optgroup label="EAST">
             <option>Testing1</option>
                <option>Testing2</option>
                <option>Testing3</option>
                <option>Testing4</option>
            </optgroup>
            <optgroup label="NORTH">
                <option>Testing5</option>
                <option>Testing6</option>
                <option>Testing7</option>
                <option>Testing8</option>
            </optgroup>
            <optgroup label="SOUTH">
                <option>Testing9</option>
                <option>Testing10</option>
                <option>Testing11</option>
                <option>Testing12</option>
            </optgroup>
       </select>

You can handle create event of multiselect widget and change labels for checkboxes in it: 您可以处理多选小部件的create事件并更改其中复选框的标签:

$(".multiselect").multiselect({
    selectedList: 10,
    noneSelectedText: 'Select Options',
    header: false,
    show: ['slide', 100],
    hide: ['explode', 100],
    //explode,bounce
    height: 200,
    multiple: true,
    autoOpen: false,
    position: {
        my: 'center',
        my: 'top',
        at: 'center',
        at: 'bottom'
    },
    create: function(event, ui) {
        var checkBoxes = $(this).multiselect("widget").find(":checkbox");
        checkBoxes.each(function() {
            var caption = $(this).next("span");
            var groupText = $(this).parents("li").prevAll(".ui-multiselect-optgroup-label:first").text();
            caption.text(groupText + " - " + caption.text());
        });
    }
});​

JSFiddle link JSFiddle链接

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在胡子中使用jQuery multiselect同时显示组名和下拉列表项 - How to display Group name also along with dropdown list items using jquery multiselect in mustache 如何在jQuery中添加/删除下拉多选列表项 - How to add/remove dropdown multiselect list items in jquery 如何使用jQuery在标签中显示多选下拉列表的选定文本? - How to display selected text of multiselect dropdown in label using jquery? 如何使用jQuery从多选下拉列表中打印选定的值? - how to print selected values from multiselect dropdown list using jquery? 如何使用jQuery将选定项从一个下拉组列表(optgroup)移动到另一个下拉组列表(optgroup)? - How to move selected items from one dropdown group list (optgroup)to another dropdown group list (optgroup) using jquery? 如何使用jQuery验证引导多选下拉列表 - How to validate bootstrap multiselect dropdown using jquery 如何使用jQuery在多选下拉菜单中设置值? - How to set value in multiselect dropdown using jQuery? 如何传递后端数据以显示为多选下拉菜单项(已附加Jsfiddle) - How to pass backend data to display as multiselect dropdown items (Jsfiddle attached) 使用Knockout.js如何从数组中的多选下拉列表中提取所选项目 - Using Knockout.js how to extract selected items from a multiselect dropdown list in an array jQuery multiselect下拉列表,包含所选项目的关闭按钮 - jQuery multiselect dropdown with close button for selected items
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM