C# autocomplete

來源:互聯網
上載者:User

標籤:html   nbsp   map   min   orm   擷取   eva   ack   span   

前台代碼

  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head runat="server">
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  5. <title></title>
  6. <script src="jquery-1.10.2.min.js"></script>
  7. <link href="jquery-ui-1.12.1.custom/jquery-ui-1.12.1.custom/jquery-ui.css" rel="stylesheet" />   // 需要引的檔案
  8. <script src="jquery-ui-1.12.1.custom/jquery-ui-1.12.1.custom/jquery-ui.min.js"></script>
  9. </head>
  10. <body>
  11. <form id="form1" runat="server">
  12. <div>
  13. <input type="text" id="ado"/> // 文字框
  14. </div>
  15. </form>
  16. </body>
  17. <script type="text/javascript">
  18. $(function () {
  19.   $("#ado").autocomplete({
  20.   minLength: 1,
  21.        // 通過函數來擷取並處理資料來源
  22.        source: function (request, response) {   // 這裡的request代表需要傳的東西,response是為了將資料展示給autocomplete
  23.        $.post("hander.ashx", { data: request.term }, function (msg) {      // 這裡ajax非同步請求資料返回一個json串
  24.              var dd = eval("(" + msg + ")");   // 這裡將json字串裝換成json對象
  25.              var arry = new Array();     //聲明了一個數組
  26.              $.each(dd.data, function (i, list) {   //遍曆json對象把json裡的資料添加到數組裡
  27.              arry.push(list.Cname)
  28.        });
  29.       response($.map(arry, function (item) { return { value: item } }));  //把數群組轉換成 value:item 格式,然後給response展示出來
  30. });
  31. }
  32. });
  33. });
  34. </script>
  35. </html>

  至於獲後台資料就不寫了,你們自己寫吧!

C# autocomplete

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.