我遵循一个教程,它使用js文件来动态静态页面,我逐字输入了所有内容,但是当我用浏览器打开它时,我的页面仍然是静态的。我把HTML文件和js文件放在同一个目录中。
JS和文件
//some great message options
const vibes = [
"... and you are awesome!",
"... have an amazing day!",
"... love to see you win!",
"... can't wait to see what you accomplish today!",
"... You got this!"
];
var vibe = vibes[Math.floor(Math.random() * Math.floor(vibes.length))];
// diplay a good vibe
document.querySelector(".vibe").append(vibe);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>A page for you</title>
<style>
body{
text-align:center;
}
div.container{
width: 400px;
margin: 0 auto;
}
.love{
font-size: 4em;
}
</style>
</head>
<body>
<div class="container">
<h1>This is a page for you</h1>
</div class="vibe">You are great!</div>
<div class="love">
❤️
</div>
</div>
<script type="text/javascript" src="vibe.js"></script>
</body>
</html>
如何让html文件选择js脚本并对消息进行随机化?
发布于 2021-12-04 20:28:53
解决这个问题;
</div class="vibe">You are great!</div>
它应该是
<div class="vibe">You are great!</div>
https://stackoverflow.com/questions/70229145
复制相似问题