jquery Plugin AutoComplete use

Source: Internet
Author: User

Files installed/required for introduction

<script type= "Text/javascript" src= ". /js/jquery-1.8.3.min.js.js "></script>

<link href= ". /plug/autocomplete/styles.css "type=" Text/css "rel=" stylesheet "/>
<script type= "Text/javascript" src= ". /plug/autocomplete/jquery.autocomplete.js "></script>

Here is my relative path, the reader to use their own corresponding correct path

<input type= "text" id= "AutoComplete" value= "All"/>

elements that use plug-ins

OK, the following mainly from two aspects of the change plugin use: Local data, Ajax dynamic access to data

Local data

var countries = [
{value: ' American ', data: ' Us '},
{value: ' Chinese ', Data: ' ZH-CN '},
// ...
{value: ' 中文版 ', data: ' En '}

$ (' #autocomplete '). AutoComplete ({
Onselect:function (suggestion) {
Alert (' You selected: ' + Suggestion.value + ', ' + suggestion.data);

So easy!

Ajax dynamically filters Server data

$ (' #autocomplete '). AutoComplete ({
Gets the URL of the server data
Serviceurl: ' Http://www.baidu.com/api ',
The parameter name passed to the server keyword, similar to the filter in the AJAX request $.post (URL, {' Filter ': keywords}, function () {})
ParamName: ' Filter ',
Transformresult:function (response) {
Parse the JSON string that the server passed over
var obj = $.parsejson (response);
return {
Suggestions: $.map (obj.list, function (DataItem) {
return {value:dataItem.right, data:dataItem.left};
Data processing after checking values
Onselect:function (suggestion) {

jquery Plugin AutoComplete 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.