在下面的代碼中,我對三個不同的事件(焦點,選擇,更改)具有相同的功能。這似乎是多餘的,但我無法弄清楚如何將三者結合爲一體。提前感謝您的任何想法!如何在jQuery UI自動完成中組合多個事件?
$("input[name^='addSchool']").autocomplete({
source: function (request, response) {
var temp = $("input[name^='addSchool']").attr("name");
var tempteacherID = temp.split(":");
var teacherID;
teacherID = tempteacherID[1]
$.ajax({
url: "JSONschools.asp",
dataType: "json",
data: { term: request.term, teacherID: teacherID },
success: function (data) {
response(data);
}
});
},
focus: function (event, ui) {
//if the value of the textbox does not match a suggestion, clear its value
if (!ui.item) {
$(this).val('');
$(this).parent("li").next().html("Please select only from the list shown").effect("pulsate", { times: 3 }, "slow");
}
else {
$(this).next().val(ui.item.id);
}
},
select: function (event, ui) {
//if the value of the textbox does not match a suggestion, clear its value
if (!ui.item) {
$(this).val('');
$(this).parent("li").next().html("Please select only from the list shown").effect("pulsate", { times: 3 }, "slow");
}
else {
$(this).next().val(ui.item.id);
}
},
change: function (event, ui) {
//if the value of the textbox does not match a suggestion, clear its value
if (!ui.item) {
$(this).val('');
$(this).parent("li").next().html("Please select only from the list shown").effect("pulsate", { times: 3 }, "slow");
}
else {
$(this).next().val(ui.item.id);
}
},
minLength: 2
});
謝謝!工作得很好。 – Paul 2010-07-20 00:26:49