"Pascal" : [
{"Name": "Pascal made simple","price":"700"},
{"Name": "Guide to pascal","price":"400"},
{"Name": "Pascal for all","price":"500"}],
"Scala" : [
{"Name":"Scala for Dummies","price":"1000"},
{"Name":"Scala in Depth","Price":"1300"}]
请帮我在javascript中编写for循环,将Pascal的书籍显示为HTML表格。
答案 0 :(得分:0)
只需循环遍历书籍并将其添加为html:
function booksToTable(books) {
var html = ['<table>'];
for (var i = 0, l = books.length; i < l; i++) {
var book = books[i];
html.push('<tr><td>' + book.Name + '</td><td>' + book.price + '</td></tr>');
}
html.push('</table>');
return html.join('\n');
}
document.write(booksToTable(input.Pascal));