[英]JSFiddle - Why is this JQuery Autocomplete not working?
這段代碼有什么問題? 為什么這個JSfiddle不起作用?
HTML
<input id="university" name="university" type="text" />
Java腳本
$(function () {
var jsonsample = [{
"name": "Stanford University"
}, {
"name": "Santa Clara University"
}]
$('#university').autocomplete({
minLength: 2,
source: 'jsonsample',
focus: function (event, ui) {
$('#university').val(ui.item.name);
return false;
},
select: function (event, ui) {
$('#university').val(ui.item.name);
return false;
}
})
.data("autocomplete")._renderItem = function (ul, item) {
return $("<li></li>")
.data("item.autocomplete", item)
.append("<a>" + item.name + "</a>")
.appendTo(ul);
};
});
jsfiddle.net/venomoustoad/9yBcZ
為什么我會收到“請使用POST請求”?
理想情況下,我正在尋找要使用jsonsample對象中的名稱填充的自動填充功能。
您將源代碼作為字符串,不應包含引號
source: 'jsonsample',
刪除它們
source: jsonsample,
您似乎輸入了錯誤的演示
.data( "autocomplete" )._renderItem = function( ul
它應該是
.data( "ui-autocomplete" )._renderItem = function( ul
你需要在數組中有一個值
[{
"value": "Stanford University"
"name": "Stanford University"
}, {
JSFiddle: http : //jsfiddle.net/NsBGH/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.