Changing HTML datalist autocomplete behavior

笑着哭i 提交于 2019-12-10 22:43:45

问题


I'm trying to implement a search autocomplete feature for a website I am working on. I am using HTML datalist, with the options generated dynamically from a backend MySQL database (communicating with AJAX). However, the datalist autocomplete isn't working like I want it to. The autocomplete seems to automatically ignore results if the keywords are not in order.

For example, if I wanted to search for the string "apple banana orange", and typed in "apple orange" in the search box, the string would not show up, even though it is one of the options generated by my backend.

I'm assuming that this is some kind of inherent datalist functionality. I was wondering if there was any way around this, or if anyone had some alternative ideas on how to implement a search autocompletion feature that will overcome this problem?

Thanks for any help.


回答1:


Have you considered jQuery autocomplete? and still using Ajax to dynamically generate the values.

<form id="searchbox">
<input id="search" type="text" placeholder="Type here" class='search_input' >
</form>

$(document).ready(function() {
$("input#search").autocomplete({
source: ["apple","banana", "orange"]
});
});

JSFiddle



来源:https://stackoverflow.com/questions/15210753/changing-html-datalist-autocomplete-behavior

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!