-2

我正在开发一个邮件系统,我想通过文本框搜索电子邮件并在用户输入第一个字母时给出一些建议。

我怎样才能做到这一点,你能帮帮我吗?

4

2 回答 2

2

有几种方法可以实现这一点。这是一个简单的asp中自动完成文本框的示例,但建议您使用jquery及其autocomplete()更简单的功能:

<!doctype html>
<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.0/themes/base/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
  <script src="http://code.jquery.com/ui/1.10.0/jquery-ui.js"></script>

  <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>
于 2013-02-10T09:20:09.720 回答
0

您想使用 TextBox.AutoCompleteMode 属性。

var source = new AutoCompleteStringCollection();
source.AddRange(new string[]
                {
                    "January",
                    "February",
                    "March",
                    "April",
                    "May",
                    "June",
                    "July",
                    "August",
                    "September",
                    "October",
                    "November",
                    "December"
                });

//Add datasource to textbox
textbox.AutoCompleteCustomSource = source;
textbox.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
textbox.AutoCompleteSource = AutoCompleteSource.CustomSource;
于 2013-02-10T08:55:22.500 回答