案例:jQuery UI案例     状态:可编辑再运行    进入竖版
 运行结果 
AخA
 
1
<!doctype html>
2
<html lang="en">
3
<head>
4
  <meta charset="utf-8">
5
  <title>jQuery UI 自动完成(Autocomplete) - 远程 JSONP 数据源</title>
6
  <link rel="stylesheet" href="/css/jqu1.10.4/jquery-ui.min.css">
7
  <script src="/js/jqu/jquery.min1.10.2.js"></script>
8
  <script src="/js/jqu/jquery-ui.min1.10.4.js"></script>
9
  <link rel="stylesheet" href="jqueryui/style.css">
10
  <style>
11
  .ui-autocomplete-loading {
12
    background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat;
13
  }
14
  #city { width: 25em; }
15
  </style>
16
  <script>
17
  $(function() {
18
    function log( message ) {
19
      $( "<div>" ).text( message ).prependTo( "#log" );
20
      $( "#log" ).scrollTop( 0 );
21
    }
22
 
23
    $( "#city" ).autocomplete({
24
      source: function( request, response ) {
25
        $.ajax({
26
          url: "http://ws.geonames.org/searchJSON",
27
          dataType: "jsonp",
28
          data: {
29
            featureClass: "P",
30
            style: "full",
31
            maxRows: 12,
32
            name_startsWith: request.term
33
          },
34
          success: function( data ) {
35
            response( $.map( data.geonames, function( item ) {
36
              return {
37
                label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
38
                value: item.name
39
              }
40
            }));
41
          }
42
        });
43
      },
44
      minLength: 2,
45
      select: function( event, ui ) {
46
        log( ui.item ?
47
          "Selected: " + ui.item.label :
48
          "Nothing selected, input was " + this.value);