JQuery Autocomplete Where the Results are Links

后端 未结 1 1861

I am trying to create a JQuery Autocomplete box where the words being suggested for autcomplete are links (similar to what happens on Facebook or Quora).

Basically,

相关标签:
1条回答
  • 2020-12-04 15:16

    This is simple. Change your source to an array of objects, such as:

    var source = [ { value: "www.foo.com",
                     label: "Spencer Kline"
                   },
                   { value: "www.example.com",
                     label: "James Bond"
                   },
                   ...
                 ];
    

    The just use the select method to redirect to the 'value', e.g.:

    $(document).ready(function() {
        $("input#autocomplete").autocomplete({
            source: source,
            select: function( event, ui ) { 
                window.location.href = ui.item.value;
            }
        });
    });
    
    0 讨论(0)
提交回复
热议问题