0

鉴于此示例,http://jsfiddle.net/CezarisLT/KHqQm/

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

 $(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,
                                 select: function( event, ui ) {
                                  }
    });
  });

如何让不在自动完成源列表中的文本在按下回车键后发出警报?例如,如果我在文本区域中输入了“hello world”,但它不在选项列表中,我如何才能在按回车键后让 hello world 发出警报?

4

1 回答 1

0

添加一个事件处理程序来检查输入中按下的键,并在输入键上提醒输入值:

$( "#tags" ).on('keyup', function(e) {
      if (e.which == 13) alert(this.value);
  }).autocomplete({
      source: availableTags,
      select: function( event, ui ) {

      }
});
于 2013-02-09T21:28:53.263 回答