-1
我有以下的javascript:如何填補JavaScript數組
var SeatSection,
firstClassSeats = [0, 0, 0, 0, 0, 0],
EconomySeats = [0, 0, 0, 0, 0, 0];
function check() {
SeatSection = parseInt(document.getElementById('number').value);
if (SeatSection == 1) {
firstClass();
} else if (SeatSection == 2) {
Economy();
} else {
Other();
}
}
function firstClass() {
for (var i = 0; i <= 5; ++i) {
if (firstClassSeats[i] == 0) {
window.alert("been assigned to seat " + i);
firstClassSeats[i] == 1;
break;
}
};
}
我有它,以便輸入數字「1」時,它會調用頭等功能。然而,在第一類函數中,我希望它從0到5循環,並且如果firstclassseats數組中的第一個元素等於0,則預訂座位。那麼它應該將該元素更改爲等於1並檢查下一個元素是否等於0並預訂該座位等。無法知道如何將預訂席位保存到陣列,並將計數增加1以轉到下一個firstclassseats數組元素。
有什麼建議嗎?
即使是基本的代碼編輯器軟件的代碼格式。你使用的是哪個代碼編輯器。 – Exception