Keep picture with Selectmenu of jQuery UI

后端 未结 4 1088
孤独总比滥情好
孤独总比滥情好 2021-01-26 12:38

I use jquery UI - Select Menu to build a List with picture. I follow this link and it\'s good. But When you select an item, just the text is copying, not the picture. I explain

4条回答
  •  隐瞒了意图╮
    2021-01-26 13:05

    I added few updates for keep Icon when selected the item. Working Perfect.

    $(function () {
                    $.widget("custom.iconselectmenu", $.ui.selectmenu, {
                        _renderItem: function (ul, item) {
                            var li = $("
  • "), wrapper = $("
    ", { text: item.label }); if (item.disabled) { li.addClass("ui-state-disabled"); } $("", { style: item.element.attr("data-style"), "class": "bl-icon " + item.element.attr("data-class") }) .appendTo(wrapper); return li.append(wrapper).appendTo(ul); } }); $("#IconDropdown").iconselectmenu({ create: function (event, ui) { var widget = $(this).iconselectmenu("widget"); $span = $(' ').html(" ").appendTo(widget); $("#" + this.id + 'selected').attr("class", $("#IconDropdown option:selected")[0].getAttribute('data-class')); }, change: function (event, ui) { $("#" + this.id + 'selected').attr("class", ui.item.element[0].getAttribute('data-class')); } }).iconselectmenu("menuWidget").addClass("ui-menu-icons"); });
提交回复
热议问题