JQuery multiselect checkbox dropdown event handling

早过忘川 提交于 2020-01-17 03:39:05

问题


I have the following code for JQuery multi select checkbox dropdown.

I can catch the event when the user selects the checkboxes. But I want the event to be fired when the user selects checkboxes and closes the dropdown ? I don't want to insert the DB for every checkbox selection , rather when the user selects his checkboxes and closes the dropdown ? And also should be able to retrieve the selected values. Thanks

<div id="multiCheckbox">
    <select name="busiUnit" id="day" multiple="multiple"
        data-native-menu="false">
        <option>Business Unit</option>
        <option value="1">Finance</option>
        <option value="2">R&D</option>
        <option value="3">Sales</option>
        <option value="4">Inventory</option>
    </select>
</div>

JS Code:

$("#day").change(function () {
    var str = '',
        busiArray = array();

    $("select#day option:selected").each(function () {
        str = $( this ).text();
        busiArray.push(str);
    });
});

回答1:


Multiple-select selectmenu is converted into a popup. That popup receives id of select And -listbox added to it dynamically.

Attach popupafterclose and then run your code.

$(document).on("popupafterclose", "#day-listbox", function () {
    /* code */
});


来源:https://stackoverflow.com/questions/26698343/jquery-multiselect-checkbox-dropdown-event-handling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!