How to select an option in a jQuery ui selectmenu dynamically?

后端 未结 6 1277
别跟我提以往
别跟我提以往 2021-02-18 21:44

After changing a menu from a regular select to a jQuery selectmenu, I can no longer select options in it programatically. Is there a way to do this?

The code to select

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-18 22:25

    I have tried the following, and it does not work in my situation

    1.

    $('#ListId').val(value);
    $('#ListId').selectmenu("refresh");
    

    2.

    $('#ListId').selectmenu("value", value);
    

    3.

    var option = $("#ListID option")
    option.attr("selected", true);
    // option.prop("selected", true);
    // option.attr("selected", "selected");
    // option.prop("selected", "selected");
    $('#ListId').selectmenu("refresh");
    

    refresh, selected ....etc. and in some situation it does not work.

    Therefore, I press ctrl+I in chrome to see the source code. and I use the following code to solve my situation.

    // Set Component Separator   jQuery UI SelectMenu
    componentSeparatorPlaceHolder.find(".ui-selectmenu-text").html(inputComponentSeparatorStr); 
    // Set ComponentSeparatorDropDown
    componentSeparator.val(inputComponentSeparatorStr); 
    

提交回复
热议问题