main.html <html> <body> <h2>Summary of booking</h2> <mce:script language ="javascript" src = "my.js"></mce:script> <mce:script language = "javascript" type="text/javascript"><!-- // src="my.js"> 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 17:55"); londonOdeon.addBooking(324, "Beci Smith", "Shrek", "29 July 2009 20:15"); document.write(londonOdeon.getBookingsTable()); // --></mce:script> </body> </html> my.js // JScript source code // CustomerBooking class 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; } //var first = new CustomerBooking(1234, "Robert Smith", "Raging Bull", "25 July 2004 18:20"); //var second = new CustomerBooking(1244, "Arnol Palmer", "Toy Story", "27 July 2004 20:15"); //document.write("1st booking person name is " + first.getCustomerName() + "<br>"); //document.write("2nd bookinf person name is " + second.getCustomerName() + "<br>"); //class cinema 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 bookingsTableHTML = "<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>"; bookingsTableHTML += "</tr>"; } bookingsTableHTML += "</table>"; return bookingsTableHTML; } 没什么技术含量,只是初学的一些语法,感觉不错,记录写下来