jquery AutoComplete Auto-complete

Source: Internet
Author: User
Tags jquery ui autocomplete

Write in front

AutoComplete is a plugin in jQueryUI.

The effect and description can be accessed here, acting like an automatic hint when searching:

I believe that the use of jquery AutoComplete Auto-complete function of the students have a lot, but often we correspond to the needs of different, and some just for the sake of easy, knock two words there is a bunch of information to choose from, but not all the demand is such, we have such a demand, knocking two words, Bind the entity that corresponds to the text.

The main parameters

The common parameters of JQuery UI autocomplete are:

    1. Source: Used to specify the data source, type string, Array, Function
      1. String: Server-side address for Ajax requests, return Array/json format
      2. Array: string arrays or JSON arrays
      3. Function (Request, Response): Obtains the input value by Request.term, response ([Array]) to render the data; (Jsonp is this way)
    2. MinLength: Activates autocomplete when the string length in the input box reaches MinLength
    3. AutoFocus: When the AutoComplete selection menu pops up, the first one is automatically selected
    4. Delay: That is, how many milliseconds are delayed to activate AutoComplete

Other infrequently used is not listed.

Files that need to be referenced

<link href= "/content/jquery.autocomplete.css" rel= "stylesheet" type= "Text/css"/> <script type= "text/ JavaScript "src="/scripts/jquery.autocomplete.js "></script> <script type=" Text/javascript ">functionInitautocomplete (JSON) {$ ("#inputxt"). AutoComplete (JSON, {minchars:1, Width:260, DataType:"JSON", Matchcontains:true, Formatitem:function(row, I, max) {returnRow.id + "<" + Row.title + ">"; }, Formatmatch:function(row, I, max) {returnRow.title; }, FormatResult:function(row) {returnRow.title; }}). Result (function(event, row, formatted) {$ ("#newid"). Val (row.id);        }); ; } $ (document). Ready (function () {            $("#inputxt"). Focus (function() {$.post ("/ashx/accessdate.ashx", {},function(data) {initautocomplete (data); }, "JSON");        });    }); </script>

Front desk:

<form action= "" method= "POST" >
<type= "text" ID= "Inputxt"/>< type= "hidden" id= "newid"/>
<input type= "Submit" value= "Submission"/>
</form>

This code means that after the text box entered the search text, smart prompt out the corresponding list and the list of the corresponding ID, select a bar, the ID assigned to the hidden field, so that the form can be submitted when the text box content and ID

Submitted together.

Background:

JavaScriptSerializer JSS =NewJavaScriptSerializer (); Dictionary<string,string> Drow =Newdictionary<string,string>(); List<Dictionary<string,Object>> gas =Newlist<dictionary<string,Object>>(); stringStart = System.Web.HttpUtility.UrlDecode (context. request["Start"], Encoding.UTF8); stringEnd = System.Web.HttpUtility.UrlDecode (context. request["End"], Encoding.UTF8); SqlConnection Con=NewSqlConnection (Sqlhelper.sqlcon);SqlDataAdapter da =NewSqlDataAdapter ("SELECT ID, Title, start, [end], UserID, FullName, Confname, Confshortname, AllDay, topic, [description] from UserD Ate", con); DataSet DS=NewDataSet (); Da.            Fill (DS); Con.            Close ();  for(inti =0; I < DS. tables[0]. Rows.Count; i++) {Dictionary<string,Object> Drow2 =Newdictionary<string,Object>(); Drow2. ADD ("ID"Ds. tables[0]. rows[i]["ID"].                ToString ()); Drow2. ADD ("title"Ds. tables[0]. rows[i]["Title"]. ToString ());Gas .            ADD (DROW2); } context. Response.Write (JSS. Serialize (gas)); 

  

The effect is like this, the following the required documents to serve

Click to download

jquery AutoComplete Auto-complete

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.