当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - jQuery Text Completer

问题描述:

I would like to add text completer in fields of my form. I don't really know how they call it, I just thought the closest would be "text completer".

What I want it to do is very simple. Let say I want to write "Broken DC Jack". I want my code to start guessing what I am going to write and give me up to 3 selections when I write "Broken". Example; "Broken CPU", "Broken Memory", "Broken DC Jack" so I can choose which ever I want then I don`t have to continue writing whole phrase, it adds itself.

网友答案:

If you're aren't up for implementing your own. jQueryUI has a pretty decent autocomplete with examples.

http://jqueryui.com/demos/autocomplete/

<script>
    $(function() {
        var availableTags = [
            "ActionScript",
            "ColdFusion",
            "Erlang",
            "Fortran",
            "Groovy",
            "Haskell",
            "Java",
            "JavaScript",
            "Lisp",
            "Perl",
            "PHP",
            "Python",
            "Ruby",
            "Scala",
            "Scheme"
        ];
        $( "#tags" ).autocomplete({
            source: availableTags
        });
    });
    </script>



<div class="demo">

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

</div><!-- End demo -->



<div class="demo-description" style="display: none; ">
<p>The Autocomplete widgets provides suggestions while you type into the field. Here the suggestions are tags for programming languages, give "ja" (for Java or JavaScript) a try.</p>
<p>The datasource is a simple JavaScript array, provided to the widget using the source-option.</p>
</div><!-- End demo-description -->
网友答案:

It's called auto-complete

JQuery UI has this widget, check this out

网友答案:

You're looking for this: http://jqueryui.com/demos/autocomplete/

分享给朋友:
您可能感兴趣的文章:
随机阅读: