How to customize jquery autocomplete for displaying in a DIV

旧时模样 提交于 2019-12-05 00:54:42

问题


I'm just wondering, I have used autocomplete plugins before but the example on jquery's website seems very simple and useful:

$(function() {
    var availableTags = [
        "ActionScript",
        "AppleScript",
        "Asp",
        "BASIC",
        "C",
        "C++",
        "Clojure",
        "COBOL",
        "ColdFusion",
        "Erlang",
        "Fortran",
    ];
    $( "#tags" ).autocomplete({
        source: availableTags
    });
});



    <div class="demo">
<div class="ui-widget">
    <label for="tags">Tags: </label>
    <input id="tags">
</div>
</div>

However, the results posted are each in input boxes. And when you click away from the results they disappear.

1) I need the results to not disappear, as long as there is text in the input that matches some values in the array, it needs to always display it.

2) The results should appear as divs. I don't need the functionality of clicking on the option and having it appear in the textbox. I'm really just trying to make a dynamic instant search.

Regards, taylor.


回答1:


Funny hack to keep the auto-complete open (this doesn't answer your question but maybe it can be useful in getting there):

http://jsfiddle.net/WUxPd/

$("#tags").autocomplete({
    source: availableTags,
    close: function(event, ui) {
        $('.ui-autocomplete').css('display', 'block')
    }
    });


来源:https://stackoverflow.com/questions/5915496/how-to-customize-jquery-autocomplete-for-displaying-in-a-div

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