Bootstrap typeahead - How to set the default value manually

后端 未结 3 1470
情话喂你
情话喂你 2021-01-12 07:34

I tried this:

$(\"#typeahead_object\").val(\"test\");

It only changes the textbox value but doesn\'t trigger the \'updater\' function

相关标签:
3条回答
  • 2021-01-12 07:40

    You could manually trigger a keyup event on the input element, after setting the value:

    $("#typeahead_object").val('test').focus().trigger('keyup')
    
    0 讨论(0)
  • 2021-01-12 07:56

    As of typeahead.js 0.10.5, this works :

    $('#typeahead_object').typeahead('val', 'some value').blur()

    0 讨论(0)
  • 2021-01-12 07:58

    To change typeahead input value, use the following construction:

    $(input).typeahead('val',value);
    

    So, in your case it should looks like:

    $("#typeahead_object").typeahead('val',"test");
    

    typeahead API documentation is available on https://github.com/twitter/typeahead.js/blob/master/doc/jquery_typeahead.md#datasets

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