我想要的最终结果是“今天的啤酒风格是:“啤酒风格”。当我输入javascript代码时,“今天的啤酒风格是:”消失。我不知道为什么。下面是代码。
HTML 代码
<!DOCTYPE html>
<html lang="en">
<head>
<!-- The Homebrewery
Author: Chris Stastny
Date: October 27th, 2015
-->
<meta charset="utf-8">
<title>The Homebrewery - Homebrewing</title>
<meta name="description" content="The Homebrewery - Homebrewing">
<meta name="author" content="Chris Stastny">
<link href="final.css" rel="stylesheet" type="text/css" />
<script src="modernizr-1.5.js"></script>
<script src="beerStyle.js"></script>
</head>
<header>
<h1> The Homebrewery</h1>
<nav>
<ul>
<li><a href="#">About</a></li>
<li><a href="#">Equipment</a></li>
<li><a href="#">Brew Log</a></li>
<li><a href="#">Links</a></li>
<li><a href="#">Newsletter</a></li>
</ul>
</nav>
</header>
<body>
<h2>Greetings!</h2>
<div id="dateBox">
Today Beer Style is:
<script>
document.getElementById("dateBox").innerHTML=style[new Date().getUTCDate()];
</script>
</div>
<br>
<img src="beer.jpg" alt="beer">
<p>This website was built to keep people informed about my homebrewing adventures. It will have brewday pictures, videos (possibly) in the future, recipes and general homebrewing information. There is also a newsletter that you can sign up for that will go into more detail about what is going on with my brewing.</p>
<br>
<footer>The Homebrewery - Homebrewing - 2015</footer>
</body>
</html>
最佳答案
当你这样做时:
document.getElementById("dateBox").innerHTML=style[new Date().getUTCDate()];
您正在用您想要添加的内容替换该 div 内的所有内容
尝试:
document.getElementById("dateBox").innerHTML += style[new Date().getUTCDate()];
关于javascript - 删除文本的脚本 - JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33532526/