jQuery UI autocomplete select event not working with mouse click

前端 未结 9 849
星月不相逢
星月不相逢 2020-12-28 15:09

I have a list of links, and I have this search box #reportname. When the user types in the search box, autocomplete will show the text of the links in a list.



        
9条回答
  •  星月不相逢
    2020-12-28 15:47

    Thanks to @William Niu and firebug, I found that the select event parameter 'ui' contains the complete selected value: ui.item.value. So instead of depending on jquery UI to change the text of the textbox, which didn't happen if the user clicks with mouse, I just pick up the selected value from 'ui':

    $("#reportname").autocomplete({
        select: function (event, ui) {
            var reportname = ui.item.value
            var thelinks = $('a.large:contains("' + reportname + '")').filter(
                function (i) { return (this.text === reportname) })
            window.location = thelinks[0].href
        };
    })
    

提交回复
热议问题