我在 jquery 中有这段代码:
$(document).ready(
function () {
var reservations = [{
"HotelId": "01",
"HotelName": "ספא וילג' הוטל",
"ReservNum": "0166772",
"Guest Name": "רוני לוי",
"Room": "323",
"Type": "SUIT",
"Rooms": "1",
"Board": "HBDB",
"Status": "CN",
"Pax": "2,0,0,0",
"Arrival": "07/08/12",
"Departure": "12/08/12",
"AgentDesc": "FIT",
"AgentCode": "FIT",
"Group": null,
"Balance": "0",
"Requests": "",
"Remarks": "1424 ש ח חצי פנסיון+2טיפולים",
"Fit/Group": "FIT",
"ReturnGuestName": "רוני לוי",
"StatusColor": "LightGreen"
},
{
"HotelId": "01",
"HotelName": "ספא וילג' הוטל",
"ReservNum": "0166778",
"Guest Name": "ולדה קאטם",
"Room": "028",
"Type": "LOCK",
"Rooms": "1",
"Board": "BLUE",
"Status": "IH",
"Pax": "2,0,0,0",
"Arrival": "07/08/12",
"Departure": "07/08/12",
"AgentDesc": "מנויים חמת גדר",
"AgentCode": "001",
"Group": null,
"Balance": "0",
"Requests": "",
"Remarks": "761 ש ח כ+ט+א*2",
"Fit/Group": "FIT",
"ReturnGuestName": "",
"StatusColor": "LightCoral"
}];
var tbody = $('#reservations tbody');
var props = ["ReservNum", "Guest Name", "Status", "Arrival", "Departure", "Type"];
$.each(reservations, function (i, reservation) {
var tr = $('<tr>');
$.each(props, function (i, prop)
{
if (reservation[prop] == "CN")
{
$('<td class="CN">').html(reservation[prop]).appendTo(tr);
}
else if (reservation[prop] == "IH")
{
$('<td class="IH">').html(reservation[prop]).appendTo(tr);
}
else
{
$('<td>').html(reservation[prop]).appendTo(tr);
}
});
tbody.append(tr);
});
});
在循环中我有这一行:
$('<td class="CN">').html(reservation[prop]).appendTo(tr);
这在 html 中创建了我:<td class="CN"> CN </td>
我想更改它,因为我想在 html 中制作这一行:
<td><img class="CN"> CN </td>
我已经尝试做:
$('<td><img class="CN">').html(reservation[prop]).appendTo(tr);
但它不做这项工作。
有人知道我需要在代码中更改什么吗?谢谢!