无法从index.js注入html

时间:2019-09-04 11:06:04

标签: javascript html getelementbyid

使用getElementById.innerHTML只是这样一个简单的问题:

document.getElementById('example').innerHTML = fullName;

它根本不起作用。我知道它非常简单,但我不知道它是如何工作的。

我也尝试过innerText

组成是这样的:

./index.js 
./index.html

html:

<!DOCTYPE html>
<html lang="en">
<head>
    <script src="index.js"></script>
    <title>JS Course</title>
</head>
<body>
    <p id="example"></p>
</body>
</html>

index.js

let word = 'Michal'
let word1 = 'Ruzicka'

const fullName = `${word} ${word1}`

console.log(fullName);

document.getElementById('example').innerHTML = fullName;

0 个答案:

没有答案