0

该计划是座位预订计划,第 1 行和第 2 行是头等舱,第 3-9 行是商务舱,第 10 到 13 行是经济舱。它们被初始化为 * 并在保留时变为 X。并在座位已满时提醒您。这些行将填充前 6 行,但它忽略第 7 行及以后的请求。但我知道它会转到适当的功能,因为如果我请求第 3 行的经济(无效),它会提醒我。但是,如果我要求使用第 7 行的头等舱,它将表现得好像什么都没有要求。它不会让我发布 html 代码,但它会在左侧显示为 row1-13,在顶部显示为 A - F。我使用下拉列表并将值设置为对应的选项,以使其在二维数组中的对应位置(例如,如果我选择第 5 行和座位 c,则第 5 行的值为 5,C 的值为3)

var rowSeat;

function start()
{
    rowSeat = new Array(14);

    for(var i = 0; i <rowSeat.length; i++)
    {
        rowSeat[i] = new Array(7);
    }
    var j = 65;
    for(var i = 1; i <rowSeat[0].length; i++)
    {
        rowSeat[0][i] = String.fromCharCode(j);
        j++;
    }
    rowSeat[0][0] = " ";
    for(var i = 1; i <rowSeat.length; i++)
    {
        rowSeat[i][0] = "Row "+i;

    }
    for(var i = 1; i <rowSeat.length; i++)
    {
        for(var j = 1; j <rowSeat[i].length; j++)
        {
            rowSeat[i][j] = "*";

        }
    }
    display();
    var subButton = document.getElementById("submitButton");
    subButton.addEventListener("click", assign, false);
}


function display()
{
    var results = "";
    results+="<table>"
    for(var i in rowSeat)
    {
            results+="<tr>";
        for(var j in rowSeat[i])
        {
            results += "<td>" +rowSeat[i][j]+ "</td>";
        }
        results += "</tr>";
    }
    results+="</table>"
    var show2 = document.getElementById( "show2" );
    show2.innerHTML = results;
}

function assign()
{
    var inputField = document.getElementById("classAssign");
    var classType = inputField.options[inputField.selectedIndex].value;

    if (classType == "FirstClass")
    {
    fClassSearch();
    }
    else if (classType == "Business")
    {
    bClassSearch();
    }
    else 
    {
    eClassSearch();
    }

    display();


}
function fClassSearch(){

    var inputField = document.getElementById("seatAssign");
    var seat = inputField.options[inputField.selectedIndex].value;

    var inputField2 = document.getElementById("rowAssign");
    var row = inputField.options[inputField2.selectedIndex].value;
    var test = document.getElementById( "test" );
    test.innerHTML = row +"&nbsp;&nbsp;&nbsp;"+ seat;

    if (row >2){
        var show2 = document.getElementById( "show" );
    show.innerHTML = "Invalid choice only row 1 and 2 are First Class";
    }
    else {
        if(rowSeat[row][seat] == "*")
        {
            rowSeat[row][seat] = "X";
            show.innerHTML = "Your Seat choice was accepted and Reserved";
        }
        else{
            show.innerHTML = "Your choice was already reserved please make another choice";
        }
    }
}
function bClassSearch(){
    var inputField = document.getElementById("seatAssign");
    var seat = inputField.options[inputField.selectedIndex].value;
    var inputField2 = document.getElementById("rowAssign");
    var row = inputField.options[inputField2.selectedIndex].value;

    if (row <3 ||row >9){
        var show2 = document.getElementById( "show" );
    show.innerHTML = "Invalid choice only row 3 through 9 are BusinessClass";
    }
    else {
        if(rowSeat[row][seat] == "*")
        {
            rowSeat[row][seat] = "X";
            show.innerHTML = "Your Seat choice was accepted and Reserved";
        }
        else{
            show.innerHTML = "Your choice was already reserved please make another choice";
        }
    }


}
function eClassSearch(){
    var inputField = document.getElementById("seatAssign");
    var seat = inputField.options[inputField.selectedIndex].value;
    var inputField2 = document.getElementById("rowAssign");
    var row = inputField.options[inputField2.selectedIndex].value;
    var show1 = document.getElementById( "show" );

    if (row <10){

    show1.innerHTML = "Invalid choice only rows 10 through 13 are Economy Class";
    }
    else {
        if(rowSeat[row][seat] == "*")
        {
            rowSeat[row][seat] = "X";
            show.innerHTML = "Your Seat choice was accepted and Reserved";
        }
        else{
            show.innerHTML = "Your choice was already reserved please make another choice";
        }
    }


    }


    window.addEventListener("load",start, false);

   </script>
4

1 回答 1

1

var row = inputField.options[inputField2.selectedIndex].value;

inputField.options 应该是 inputField2.options

inputField.options 仅变为 6,因为您只有 6 个座位宽,但您正试图查看座位列表中的行。

于 2013-11-05T19:52:51.233 回答