是的,它可以,因爲您提供自己的自定義回調作爲數據源。該回調可以實現你想要的行爲。
下面是我認爲你想要的一個演示。
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/ui-lightness/jquery-ui.css" type="text/css" media="all" />
<script type="text/javascript">
$(function() {
$('#myautocomplete').autocomplete({
source: function(request, response) {
// TODO: make suggestions actually depend on what the user types into the search box.
// You want two suggestions, one with 'briman57' and one with 'Brian Johnson', so we need two suggestions with different labels, but with the same value.
var suggestions = [
{ label: 'briman057' , value: 'briman057', username : 'briman057', name : 'Brian Johnson'},
{ label: 'Brian Johnson', value: 'briman057', username : 'briman057', name : 'Brian Johnson'}
];
response(suggestions);
},
select: function(event, ui) {
alert('You have selected ' + ui.item.name + ' (' + ui.item.username + ')');
}
});
});
</script>
<input id="myautocomplete" title="Enter anything here."></input>
看看Remote JSONP datasource example的源代碼獲取更多靈感。
感謝您添加編輯。我看了一下鏈接,仍然有點不清楚,但現在我明白了。 – itsmequinn 2012-02-05 01:09:22