我有一个名为reservations.js一个js文件,在这个文件我是有保留的数组,如:插入元素表中的jQuery/JS
var reservations = [
{ "HotelId": "01", "HotelName": "SPA", "ReservNum": "0166977", "Guest Name": "Jonny", "Room": null, "Type": "SUIT", "Rooms": "1", "Board": "BB", "Status": "IH", "Pax": "2,0,0,0", "Arrival": "07/08/12", "Departure": "09/08/12", "AgentDesc": "FIT", "AgentCode": "FIT", "Group": null, "Balance": "0", "Requests": "", "Remarks": null, "Fit/Group": "FIT", "ReturnGuestName": "", "StatusColor": "LightCoral" },
{ "HotelId": "01", "HotelName": "SPA", "ReservNum": "H000192", "Guest Name": null, "Room": null, "Type": "Folio", "Rooms": "0", "Board": "", "Status": "IH", "Pax": "0,0,0,0", "Arrival": "07/08/12", "Departure": "10/09/12", "AgentDesc": "movies", "AgentCode": "001", "Group": null, "Balance": "0", "Requests": "", "Remarks": "", "Fit/Group": "FIT", "ReturnGuestName": "", "StatusColor": "LightCoral" }
];
我需要做的是创造一个表格(在html中)有6个colomns:Res。号码,客人姓名,身份,到达日期,出发日期,房间类型。 并将数组中的元素插入表中的匹配列。
举例:ReservNum“: ”0166977“,于是数0166977将在 第一山坳RES数
我的表是这样的:。
<table id="reservations">
<thead>
<tr>
<th>Res. Number</th><th>Guest Name</th><th>Status</th><th>Arrival Date</th><th>Departure Date</th><th>Room Type</th>
</tr>
</thead>
<tbody>
<tr>
<td>resnum</td><td>guestname</td><td>status</td><td>arrivaldate</td><td>departuredate</td><td>roomtype</td>
</tr>
</tbody>
</table>
我不知道该怎么做 我试图在js文件中做这样的事情:
$('#reservations tr').each(function (i) {
$(this).find('td').html(reservations[i]);
});
但它不工作。 (也许我的HTML表是错误的或JS,甚至两者)。
我是新来的js/jquery,所以我有点不确定我在做什么。
在演示它看起来不错,但它并不在我的项目 工作(我正在开发microsoft visual web developer 2010 express) – shlomi
这是我的项目: js文件是: http://tinypic.com/r/f0tmt/6 html是: http://tinypic.com/view.php?pic=2rxv5at&s=6 但我在屏幕上看到的是这样的: http://tinypic.com/r/nbf9mo/6 也许我错过了这里的东西.. 非常感谢你! – shlomi
我注意到,如果我将其更改为javascript 1.7,则演示中会发生同样的情况。 也许这是我的问题。 你有没有解决我的问题在js1.7? 谢谢。 – shlomi