0
我有下面的代碼,使用jquery ui自動完成,問題是我有困難在同一頁上設置第二個自動完成。有人可以看看代碼,並讓我知道什麼是錯的?最好的一個運行正常。有人可以看看我的jQuery UI自動完成代碼,並告訴我爲什麼它只能在1個文本框上工作嗎?
$(document).ready(function() {
var AccommObject = $("[id$='_txtAccommodation_txtStandard']")[0];
var Accommid = AccommObject.id;
var AccommidFull = "#" + Accommid;
var AccommObject2 = $("[id$='_txtInvoiceNo_txtStandard']")[0];
var Accommid2 = AccommObject2.id;
var AccommidFull2 = "#" + Accommid2;
$(AccommidFull).autocomplete({
source: function(request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "RequisitionSearch.aspx/FetchAccommodationNameList",
data: '{"AccommodationName":"' + request.term + '"}',
dataType: "json",
success: function(data) {
response(
$.map(data.d, function(item) {
return {
id: item.ID,
label: item.Label,
value: item.Value,
ImageURL: item.ImageURL
};
})
);
},
error: function(result) { debugger; }
});
},
minLength: 2
});
$(AccommidFull2).autocomplete({
source: function(request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "RequisitionSearch.aspx/FetchAccommodationInvoiceNoList",
data: '{"InvoiceNo":"' + request.term + '"}',
dataType: "json",
success: function(data) {
response(
$.map(data.d, function(item) {
return {
id: item.ID,
label: item.Label,
value: item.Value,
ImageURL: item.ImageURL
};
})
);
},
error: function(result) { debugger; }
});
},
minLength: 2
});
});
這不是很具體。它會在控制檯中拋出一個javascript錯誤嗎? –
我們可以看到HTML – Bene
對不起,第二個沒有任何錯誤,它不會觸發目標方法。問題是在同一頁面上有多個自動完成實例的正確方法是什麼。由於某些原因,該事件尚未連接到第二個文本框。我已經調試過,可以看到它獲得的第二個文本框與第一個文本框完全相同,但沒有啓動。 – jazman