我的 HTML 代码没有获取本地 javascript 文件
My HTML code not picking up local javascript file
我正在学习一个使用 js 文件使静态页面动态化的教程,我逐字输入了所有内容,但当我用浏览器打开它时,我的页面保持静态。
我在同一目录中有 HTML 文件和 js 文件。
JS 和 HTML 文件
//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 脚本并随机化消息?
解决这个问题;
</div class="vibe">You are great!</div>
应该是
<div class="vibe">You are great!</div>
我正在学习一个使用 js 文件使静态页面动态化的教程,我逐字输入了所有内容,但当我用浏览器打开它时,我的页面保持静态。 我在同一目录中有 HTML 文件和 js 文件。
JS 和 HTML 文件
//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 脚本并随机化消息?
解决这个问题;
</div class="vibe">You are great!</div>
应该是
<div class="vibe">You are great!</div>