<script type='text/javascript'>
function
CustomerBooking(bookingId,customerName,film,showDate){
this.bookingId = bookingId;
this.customerName = customerName;
this.film = film;
this.showDate =showDate;
}
CustomerBooking.prototype.getBookingId =
function
(){
return
this.bookingId;
}
CustomerBooking.prototype.setBookingId =
function
(bookingId){
this.bookingId = bookingId;
}
CustomerBooking.prototype.getCustomerName =
function
(){
return
this.customerName;
}
CustomerBooking.prototype.setCustomerName =
function
(customerName){
this.customerName = customerName;
}
CustomerBooking.prototype.getFilm =
function
(){
return
this.film;
}
CustomerBooking.prototype.setFilm =
function
(film){
this.film = film;
}
CustomerBooking.prototype.getShowDate =
function
(){
return
this.showDate;
}
CustomerBooking.prototype.setShowDate =
function
(showDate){
this.showDate = showDate;
}
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></tr>"
;
}
bookingsTableHTML +=
"</table>"
;
return
bookingsTableHTML;
}
保存到cinema对象bookingFilm的属性当中,然后调用getBookingsTable方法来获取数据信息
var
bookingFilm =
new
cinema();
bookingFilm.addBooking(123,
"Jack"
,
"Love Java"
,
"1 May 2012"
);
bookingFilm.addBooking(123,
"Jack"
,
"Love Java"
,
"1 May 2012"
);
bookingFilm.addBooking(122,
"Jack"
,
"Love Java"
,
"1 May 2012"
);
bookingFilm.addBooking(121,
"Jack"
,
"Love Java"
,
"1 May 2012"
);
bookingFilm.addBooking(120,
"Jack"
,
"Love Java"
,
"1 May 2012"
);
bookingFilm.addBooking(119,
"Jack"
,
"Love Java"
,
"1 May 2012"
);
document.write(bookingFilm.getBookingsTable());
</script>