Example of jquery plug-in autocomplete usage, jqueryautocomplete

Source: Internet
Author: User

Example of jquery plug-in autocomplete usage, jqueryautocomplete

This example describes how to use the jquery plug-in autocomplete. We will share this with you for your reference. The details are as follows:

(1) Introduce js and styles

<script type="text/JavaScript" src="../js/jQuery-1.8.0.js"charset="utf-8"></script><script type="text/javascript" src="../js/jquery.autocomplete.js"charset="utf-8"></script><link href="css/jquery.autocomplete.css" rel="Stylesheet">

(2) autocomplete front-end js

<Script type = "text/javascript"> // alert ("test ");.. /search/fuzzy/pkword.html $ (document ). ready (function () {var kw = ""; $ ("# kw "). blur (function () {kw = $ ("# kw "). val () ;}); $ ("# kw "). autocomplete ("search/fuzzy/pkword.html", // request background path {parse: function (jsonData) {var parsed = []; for (var I = 0; I <jsonData. length; I ++) {parsed [parsed. length ++] = {data: jsonData [I], value: jsonData [I]. catalogName, result: jso NData [I]. catalogName}; // convert the format of the json returned in the background} return parsed;}, formatItem: function (row, I, max) {var item = "<table id = 'Auto" + I + "'class = 'A' style = 'width: 100%; '> <tr> <td align = 'left'> in <font color = 'red'> "+ row. catalogName + "</font> search by Category </td> <td align = 'right' style = 'color: green; '> about" + row. catalogCount + "result </td> </tr> </table>"; return item; // format of autocomplete prompt }}). result (function (even, item) {var catalogName = it Em. catalogName; window. open ("productList/fuzzySearch/" + catalogName + "/" + kw + ". html? Page = 1 "," _ blank "); // events when you click the mouse}); </script>

(3) return the background json with springmvc

@ResponseBody@RequestMapping(value = "/search/fuzzy/pkword.html", method = RequestMethod.GET)public List<CatalogCountBean> fuzzySearch(@RequestParam String q) {List<CatalogCountBean> list = null;System.out.println("q:" + q);list = (List<CatalogCountBean>) productListService.fuzzySearch(productListNamespace, q);return list;}

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.