Html:
1 | < input type = "text" name = "country" id = "autocomplete" /> |
Ajax 查找
1 2 3 4 5 6 | $( '#autocomplete' ).autocomplete({ serviceUrl: '/autocomplete/countries' , onSelect: function (suggestion) { alert( 'You selected: ' + suggestion.value + ', ' + suggestion.data); } }); |
本地查找 (没有 Ajax):
1 2 3 4 5 6 7 8 9 10 11 12 | var countries = [ { value: 'Andorra', data: 'AD' }, // ... { value: 'Zimbabwe', data: 'ZZ' } ]; $('#autocomplete').autocomplete({ lookup: countries, onSelect: function (suggestion) { alert('You selected: ' + suggestion.value + ', ' + suggestion.data); } }); |
自定义查找函数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | $( '#autocomplete' ).autocomplete({ lookup: function (query, done) { // Do Ajax call or lookup locally, when done, // call the callback and pass your results: var result = { suggestions: [ { "value" : "United Arab Emirates" , "data" : "AE" }, { "value" : "United Kingdom" , "data" : "UK" }, { "value" : "United States" , "data" : "US" } ] }; done(result); }, onSelect: function (suggestion) { alert( 'You selected: ' + suggestion.value + ', ' + suggestion.data); } }); |
特别申明:
本站所有资源都是由网友投稿发布,或转载各大下载站,请自行检测软件的完整性!
本站所有资源仅供学习与参考,请勿用于商业用途,否则产生的一切后果将由您自己承担!
如有侵权请联系我们删除下架,联系方式:lei1294551502@163.com