如何在asp:TextBox中实现搜索建议的ajax脚本?

时间:2013-10-21 14:20:49

标签: c#-4.0 asp.net-ajax

如何在asp.net的文本框中使用get,post calls和ActiveX对象实现搜索建议的ajax脚本?

1 个答案:

答案 0 :(得分:0)

您可以使用jquery自动完成插件,它就像魅力一样。

JQueryUI Autocomplete

    <html lang="en">
<head>
  <meta charset="utf-8" />
  <title>jQuery UI Autocomplete - Default functionality</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css" />
  <script>
  $(function() {
    var availableTags = [
      "ActionScript",
      "AppleScript",
      "Asp",
      "BASIC",
      "C",
      "C++",
      "Clojure",
      "COBOL",
      "ColdFusion",
      "Erlang",
      "Fortran",
      "Groovy",
      "Haskell",
      "Java",
      "JavaScript",
      "Lisp",
      "Perl",
      "PHP",
      "Python",
      "Ruby",
      "Scala",
      "Scheme"
    ];
    $( "#tags" ).autocomplete({
      source: availableTags
    });
  });
  </script>
</head>
<body>

<div class="ui-widget">
  <label for="tags">Tags: </label>
  <input id="tags" />
</div>


</body>
</html>

上面的示例将静态数组绑定到控件,而您也可以使用ajax调用在document.ready()中获取动态数组。