我有这段代码,我在 Firebug 中分析过,这真的让我很困惑。当我调用此代码时,该行alert(selectedAmenities);
显示正确的数据,但该行
source: "/Results/GetAmenities?selected=" + selectedAmenities,
始终显示selectedAmenities
为空字符串。为什么是这样?
$(function () {
var selectedAmenities = "";
function amenitiesLog(message) {
if (!$('#amenitiesLog div:contains(' + message + ')').length) {
$("<div/>").text(message).appendTo("#amenitiesLog");
$("<br/>").text("").appendTo("#amenitiesLog");
$("#amenitiesLog").scrollTop(0);
selectedAmenities = document.getElementById("amenitiesLog").innerHTML;
alert(selectedAmenities);
}
}
$("#Amenities").autocomplete({
source: "/Results/GetAmenities?selected=" + selectedAmenities,
minLength: 3,
select: function (event, ui) {
if (ui.item != null) amenitiesLog(ui.item.value);
}
});
});