Jquery AutoComplete Plugin Use

Source: Internet
Author: User

Easy to implement similar Baidu input box Lenovo function:

AutoComplete is a powerful plug-in that is based on jquery and can be downloaded to the latest version on the jquery website. First, the jquery UI is jquery-based, so you must first refer to the jquery Script library in your page and then reference the jquery UI library, for the jquery UI library, you can refer to the entire library, or just the library that the current page uses. The following files can be introduced directly when using AutoComplete:

    • Jquery-1.9.1.min.js
    • Jquery.ui.autocomplete.js
    • Jquery.ui.core.js
    • Jquery.ui.position.js
    • Jquery.ui.widget.js
    • Jquery.ui.menu.js

or directly into the aggregation file:

    • Jquery-1.9.1.min.js
    • Jquery-ui-1.10.3.custom.min.js
    • Jquery-ui-1.10.3.custom.min.css

Demo Html:

<id= "autocomplete"  type= "text"/>

Javascript:

//Local Data$(function () {varAvailabletags = ["ActionScript","AppleScript","Asp","BASIC",C,"C + +","Clojure","COBOL","ColdFusion","Erlang","Fortran","Groovy","Haskell","Java","JavaScript","Lisp","Perl","PHP","Python","Ruby","Scala","Scheme"];//this uses an array as the data source, and Availabletags is the name of the array.$ ("#tags"). AutoComplete ({source:availabletags});});/************* Remote Data ***************/$("#autocomplete"). AutoComplete ({Source:function(Request, Response) {$.post ("Server-side address", {Q: $ ("#autocomplete"). Val (), D:NewDate (). GetTime (), R:math.random ()},function(data) {varRedate =data.redate; if(!data.result) Redate= [{Name: "No Data", Id: "1" }]; Response ($.map (Redate,function(item) {return{Label:item. Name, Value:item. Name, Id:item.                    ID};               }));          }); }, MinLength:1, select:function(event, UI) {alert ("Id=" +ui.item.id); }          });

The server side is roughly the following, returning the JSON data:

 Public Jsonresult Getdevelopersbykeyword (string  q) {   var list = BLL. Getuserlist (q);    return Json (new {result = list. Any (), redate = list}, Jsonrequestbehavior.allowget);}
/*********** a remote data source with a cache (each request for the same data) ****************/$(function () {    varurl = "Servicehandler.ashx"; varCache ={}, LASTXHR; $("#auto"). AutoComplete ({minLength:2, Source:function(Request, response) {varterm =Request.term; if(terminchcache)                {response (cache[term]); return; } lastxhr= $.getjson (URL, request,function(data, status, XHR) {Cache[term]=data; if(XHR = = =lastxhr)                {Response (data);        }            }); }    });});

Jquery AutoComplete Plugin Use

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.