function updateRoomsList() {
//empty the rooms list
$("#rooms").empty();
//fetch the non-joined rooms, id and name
$.get('JoinPart', {
goal: 5,
userName: $("#userName").html()
}, function (responseText) {
var i = 0;
id = "";
while (i < responseText.length) {
if (responseText.charAt(i) == '.') {
//Now we got the full Id of a room, lets add it
$.get('JoinPart', {
goal: 6,
roomId: id
}, function (responseText) {
roomName = responseText;
$("#rooms").append('<div id="room' + id + '" class="listItem"><span title="Join Room" class="joinButton">+</span><div class="listItemContent">' + roomName + '</div></div>');
});
id = "";
} else {
id = id + responseText.charAt(i);
}
i++;
}
});
}
在函數訪問變量的函數內。在該函數有一個變量id
,如果我alert(id);
後不能在JavaScript
if(responseText.charAt(i)=='.')
我得到的ID在else
計算出正確的值,但是當我在做alert(id);
裏面的$.get
這個id是空的""
,意思是在append
函數中,id
沒有任何值,我怎麼能得到這個id值超出$ .get函數的值?
您是否嘗試過聲明ID您updateRoomsList功能之外,您可以測試:'VAR ID;' – j08691 2012-08-05 15:40:59