1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| <html>
<head>
<script type="text/javascript" src="jquery-ui/js/jquery-ui-1.8.6.custom.min.js"></script>
<script type="text/javascript">
$(function()
{ function log( message )
{ $( "<div/>" ).text( message ).prependTo( "#log" );
$( "#log" ).attr( "scrollTop", 0 );
}
$.ajax
({url: "london.xml",
dataType: "xml",
success: function( xmlResponse )
{ var data = $( "geoname", xmlResponse ).map(function()
{ return
{ value: $( "name", this ).text() + ", " +
( $.trim( $( "countryName", this ).text() ) || "(unknown country)" ),
id: $( "geonameId", this ).text()
};
}).get();
$( "#birds" ).autocomplete
({source: data,
minLength: 0,
select: function( event, ui )
{ log( ui.item ?
"Selected: " + ui.item.value + ", geonameId: " + ui.item.id :
"Nothing selected, input was " + this.value );
}
});
}
});
}
);
</script>
<div>
<div>
<label for="birds">London matches:
</label>
<input id="birds" />
</div>
<div style="margin-top:2em; font-family:Arial">Result:
<div id="log" style="height: 200px; width: 300px; overflow: auto;">
</div>
</div>
</div> |
Partager