1
我有一個問題,jqueryui的自動完成。當我過濾results.it的過濾詞像它包含,但我想像startswith.How可以做到嗎?(單詞來自xml文件)JqueryUi自動完成問題
謝謝。
編輯:這是我的完整JQ代碼:
$(function() {
function log(message) {
if ($("#<%=From1.ClientID %>").val() == "") {
$("#<%=From1.ClientID %>").val(message);
}
else if ($("#<%=From2.ClientID %>").val() == "")
{ $("#<%=From2.ClientID %>").val(message); }
else { $("#<%=From3.ClientID %>").val(message); }
}
function log2(message) {
if ($("#<%=To1.ClientID %>").val() == "") {
$("#<%=To1.ClientID %>").val(message);
}
else if ($("#<%=To2.ClientID %>").val() == "")
{ $("#<%=To2.ClientID %>").val(message); }
else { $("#<%=To3.ClientID %>").val(message); }
}
$.ajax({
url: "airports.xml",
dataType: "xml",
success: function (xmlResponse) {
var data = $("airport", xmlResponse).map(function() {
return {
label: $("code", this).text() + ", " + $("name", this).text() + ", " + $("city", this).text() + "/" + $("country", this).text(),
value: $("code", this).text(),
};
}).get();
var data2 = $("airport", xmlResponse).map(function() {
return {
label: $("code", this).text() + ", " + $("name", this).text() + ", " + $("city", this).text() + "/" + $("country", this).text(),
value: $("code", this).text() ,
};
}).get();
$("#<%=ToL.ClientID %>").autocomplete({
source: data2,
minLength: 2,
select: function (event, ui) {
log2(ui.item ? (ui.item.value) : "Nothing selected, input was " + this.value);
}
});
$("#<%=FromL.ClientID %>").autocomplete({
source:data,
minLength: 2,
select: function (event, ui) {
log(ui.item ? (ui.item.value) : "Nothing selected, input was " + this.value);
}
});
}
})
});