How do you set a default value with jquery auto complete combobox?

后端 未结 14 1812
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-28 19:01

When using the jquery ui autocomplete combobox, can you set a default value for the combobox?

相关标签:
14条回答
  • 2020-12-28 19:07
    input.val( $(select).children("option:selected").text());
    
    0 讨论(0)
  • 2020-12-28 19:07

    I used the below line of code instead, just another way of achieving the same result :)

    $('option:selected', this.element).text()
    
    0 讨论(0)
  • 2020-12-28 19:09

    You can achieve this by editing the following statement of the auto-completer:

    value = selected.val() ? selected.text() : "Select Institution";
    
    0 讨论(0)
  • 2020-12-28 19:11

    I've tweaked the responses here to use the select variable already defined by the combobox to find the selected option and use that. This means it is generic for which ever element you have defined the combobox on (using id, class or selector ) and will work for multiple elements also.

    input.val(select.find("option:selected").text());
    

    Hope this helps someone!

    0 讨论(0)
  • 2020-12-28 19:17

    I have an answer that worked for my implementation of the jquery UI combobox. Somewhere in the middle of the code was this:

    .val(value)
    

    I changed it to:

    .val(select.val())
    

    and presto, the initial value of the underlying textbox appeared. Seems to me like this should be the default functionality, but what do I know?

    0 讨论(0)
  • 2020-12-28 19:19

    may be this will help you

    http://forum.jquery.com/topic/autocomplete-default-value

    0 讨论(0)
提交回复
热议问题