我正在写作业,我必须制作一个页面,其中包含10本书,其中包含有关使用DOM及其封面图像的一些信息,即使我将JS文件链接到HTML文件,打开时也看不到任何内容我的HTML文件在浏览器中。我究竟做错了什么?
'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);
img.appendChild(document.createTextNode(booksObj[key]['images']));
img.src = bookImage;
}
}
booksList();
<div id="root"></div>
慕工程0101907
桃花长相依
相关分类