我想提醒“正在运行的功能大炮”,然后当我按“确定”时,我只想说“大炮船驶向 14 度”,但它一直在我的输出中打印警报。
JS
function alertMessage (message) {
alert (message);
}
alertMessage("the Battle has begun");
function alertShip (ship, number) {
alert (ship);
document.write (ship + "the ship sails off to " + number + "degrees");
}
alertShip("running function cannons", 14);
HTML
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Functions</title>
<!-- This links to the js code specific for this page -->
<script src="functions.js"></script>
</head>
<body>
<div id="output"> </div>
<div id="output2"> </div>
</body>
</html>
最佳答案
尝试从 document.write 中删除 ship 参数并将语句替换为:
document.write("加农炮船驶离 "+ number + "度");
然后,您应该能够获得所需的输出。
*p.s.: 如果您在文本编辑器上执行此操作并尝试在浏览器上运行它,您可以考虑将标签更改为:.
希望对您有所帮助!
关于javascript - 为什么我的输出重复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37401711/