Search on Click with Jquery's Autocomplete

后端 未结 5 1995
自闭症患者
自闭症患者 2021-02-14 04:20

I am trying to simulate the Youtube Autocomplete Search experience.

I can\'t find the option when the viewer clicks on a listed item and is automatically proceeded to se

5条回答
  •  没有蜡笔的小新
    2021-02-14 04:34

    I wanted similar behaviour, using jQueryui's default autocomplete widget. The trick is to use the 'select' event, but submitting from your select-handler will not give the desired results, because the input will not yet have the selection filled in.

    The following code works for me though:

    $("input#searchbox").autocomplete({
      source: autocomplete,
      select: function(event, ui) { 
        $("input#searchbox").val(ui.item.value);
        $("#searchform").submit();
      }
    })
    

    (in the example above, 'autocomplete' is a url that points to the completion source)

    Where input#searchbox is the actual input entry, and #searchform is its parent form. Basically, you need to fill the input before submitting yourself.

提交回复
热议问题