JQuery Plugin AutoComplete

Source: Internet
Author: User

A recent feature is a fuzzy query on the contents of the text box, and a drop-down box to select the contents of the fuzzy query. At the beginning of the writing, I think of the previous company encountered, using RPC (short-character poor), but I have not remember why did realized, and then various help before the colleagues. But they didn't know why did got it. Well, what to do, I asked the next colleague has encountered this similar function, how to do, the earlier asked not to waste time wasted it. So there is autocomplete. My knowledge is not wide, so now I also try to summarize, do not laugh.

Enter the topic:

Website address: api.jqueryui.com/autocomplete/

Just looked at this official website, this feature knowledge jqueryui One, there are many have been packaged well. It's too little to be seen.

Introduction of JS and CSS files required by the AutoComplete plugin

  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">   <script src="//code.jquery.com/jquery-1.10.2.js"></script>   <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>Simulating source data <script> $(function() { var availableTags = [ "ActionScript", "AppleScript", "Asp", "BASIC", "C", "C++", "Clojure", "COBOL", "ColdFusion", "Erlang", "Fortran", "Groovy", "Haskell", "Java", "JavaScript", "Lisp", "Perl", "PHP", "Python", "Ruby", "Scala", "Scheme" ]; $( "#tags" ).autocomplete({     source: availableTags }); }); </script> </head> <body> <div class="ui-widget">//主要呈现下拉框的样式引入
<label for="tags">Tags: </label> <input id="tags"> </div> </body> </html>Of course, the data in the Web is obtained from the database, source is dynamically generated $( "#autocomplete" ).autocomplete({     source: function( request, response ) {$.ajax ({URL: "",. ..,success:function (data) {//Here you see what type of data you have, and what is traversed is the value of sourceResponse ($.map (data, function (item) {return {dbId:item.dbid, JDBCURL:ITEM.JDBCURL, Ip:item.ip, port:item.port}})}})       },Select:function (Event,ui) {//Here I will select the value to the text box. However, when selected, the text box is emptied. The value is printed out is obtained, baffled its solution}, AppendTo: "#tag",//The selection box appears under that   }) ); } });Finally, the data is displayed in the panel, with its own style _renderItem: function( ul, item ) { return $( "<li>" ) .attr( "data-value", item.value ) .append( item.label ) .appendTo( ul ); }

Really is not to use this web version of the blog Park, what is to be pure input

Reference: http://www.open-open.com/lib/view/open1340957775905.html

JQuery Plugin AutoComplete

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.