set value to jquery autocomplete combobox

后端 未结 5 1542
星月不相逢
星月不相逢 2021-01-02 07:58

I am using jquery autocomplete combobox and everything is ok. But I also want to set specific value through JavaScript like $(\"#value\").val(\"somevalue\") and

5条回答
  •  醉梦人生
    2021-01-02 08:04

    I managed a quick and dirty way of setting the value. But, you do need to know both the value and the text of the item that you want to display on the dropdown.

    var myValue = foo; // value that you want selected
    var myText = bar; // text that you want to display
    // You first need to set the value of the (hidden) select list
    $('#myCombo').val(myValue);
    // ...then you need to set the display text of the actual autocomplete box.
    $('#myCombo').siblings('.ui-combobox').find('.ui-autocomplete-input').val(myText);
    

提交回复
热议问题