3 回答
TA贡献1887条经验 获得超5个赞
'use strict';
{
const booksObj = {
how_to_create_a_mind: {
title: 'How to Create a Mind: The Secret of Human Thought Revealed',
author: 'Ray Kurzweil',
language: 'english'
},
universe_from_nothing: {
title: 'A Universe from Nothing',
author: 'Lawrence M. Krauss',
language: 'english'
},
sapiens: {
title: 'Sapiens: A Brief History of Humankind',
author: 'Yuval Noah Harari',
language: 'english'
},
homo_deus: {
title: 'Homo Deus: A Brief History of Tomorrow',
author: 'Yuval Noah Harari',
language: 'english'
}
};
const root = document.getElementById('root');
function booksList() {
const div = document.createElement('div');
root.appendChild(div);
const h1 = document.createElement('h1');
div.appendChild(h1);
h1.appendChild(document.createTextNode('My List Of Books'));
for (const key in booksObj) {
const h2 = document.createElement('h2');
root.appendChild(h2);
h2.appendChild(document.createTextNode(booksObj[key]['title']));
const author = document.createElement('p');
root.appendChild(author);
author.appendChild(document.createTextNode(booksObj[key]['author']));
const language = document.createElement('p');
root.appendChild(language);
language.appendChild(document.createTextNode(booksObj[key]['language']));
const img = document.createElement('img');
root.appendChild(img);
let bookImage = img.appendChild(document.createTextNode(booksObj[key]['images']));
img.src = bookImage;
}
}
booksList();
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="style.css">
</head>
<body>
<div id="root"></div>
<script type='text/javascript' src='app.js'></script>
</body>
</html>
TA贡献1860条经验 获得超8个赞
您似乎}
在脚本末尾缺少a 。在这里查看小提琴https://jsfiddle.net/fwL0vx46/
您的代码导致unexpected end of input
异常,该异常显示在开发人员工具控制台中。
添加回答
举报