我需要帮助通过此代码查看我的错误

时间:2016-07-10 21:24:06

标签: javascript

我是一个新的教学自己JS使用JS是性感的,除其他外。我正在努力练习其中一个练习而无法找到我的错误。我在一些地方(包括这里)研究并发现了这个问题,但没有一个解决了我的问题。我跑这个时就得到了我的标题和页脚。

我会在此处粘贴我的代码,看看是否有人可以帮助我。非常感谢。

我希望我发布的是正确的,因为它看起来很奇怪。

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html lang="en">
    <head>
        <title>Chapter 5 Example 8</title>
    </head>

    <body>

    <h2>Summary of Bookings</h2>

    <script type="text/javascript"> 

//CustomerBooking type

    function CustomerBooking(bookingId, customerName, film, showDate)
    {
        this.customerName = customerName;
        this.bookingId = bookingId;
        this.showDate = showDate;
        this.film = film;
    }

    CustomerBooking.prototype.getCustomerName = function()
    {
        return this.customerName;
    }

    CustomerBooking.prototype.setCustomerName = function(customerName)
    {
        this.customerName = customerName;
    }

    CustomerBooking.prototype.getShowDate = function()
    {
        return this.showDate;
    }
    CustomerBooking.prototype.setShowDate = function(showDate)
    {
        this.showDate = showDate;
    }
    CustomerBooking.prototype.getFilm = function()
    {
        return this.film;
    }
    CustomerBooking.prototype.setFilm = function(film)
    {
        this.film = film;
    }
    CustomerBooking.prototype.getBookingId = function()
    {
        return this.bookingId;
    }
    CustomerBooking.prototype.setBookingId = function(bookingId)
    {
         this.bookingId = bookingId;
        }

    //Cinema type

    function Cinema()
    {
        this.bookings = new Array();
    }

    Cinema.prototype.addBooking = function(bookingId, customerName, film, showDate)
    {
        this.bookings[bookingId] = new CustomerBooking(bookingId, customerName, film, showDate);
    }

    Cinema.prototype.getBookingsTable = function()
    {
        var booking;
        var bookingTableHTML =  "<table border=1>";

        for (booking in this.bookings)
        {
            bookingsTableHTML += "<tr><td>";
            bookingsTableHTML += this.bookings[booking].getBookingId();
            bookingsTableHTML += "</td>)"

            bookingsTableHTML += "<td>";
            bookingsTableHTML += this.bookings[booking].getCustomerName();
            bookingsTableHTML += "</td>;"

            bookingsTableHTML += "<td>";            
            bookingsTableHTML += this.bookings[booking].getFilm();
            bookingsTableHTML += "</td>";

            bookingsTableHTML += "<td>";
            bookingsTableHTML += this.bookings[booking].getShowDate();
            bookingsTableHTML += "</td>";
            bookingsTableHTLM += "</tr>";
        }

        bookingsTableHTML += "</table>";
        return bookingsTableHTML;
    }   

    var londonOdeon = new Cinema();
    londonOdeon.addBooking(342, "Arnold Palmer", "Toy Story", "15 July 2009 20:15");
    londonOdeon.addBooking(335, "Louise Anderson", "The Shawshank Redemption", "27 July 2009 11:25");
    londonOdeon.addBooking(566, "Catherine Hughes", "Never Say Never", "27 July 2009 19:55");
    londonOdeon.addBooking(324, "Beci Smith", "Shrek", "29 Jluly 2009 20:15");

    document.write(londonOdeon.getBookingsTable()); 

</script>


    </body>
</html>

1 个答案:

答案 0 :(得分:0)

您的变量与var bookingTableHTML = "<table border=1>";类似,但您要分配到bookingsTableHTML += "<tr><td>";而不是使用bookingTableHTML += "<tr><td>";

错误是bookingTableHTML,但您使用的是bookingsTableHTML

相关问题