C# autocomplete

前台代码

  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>

  至于获后台数据就不写了,你们自己写吧!

转载于:https://www.cnblogs.com/damenge/p/8876256.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值