javascript - 为什么我的输出重复?

标签 javascript function parameters output alert

我想提醒“正在运行的功能大炮”,然后当我按“确定”时,我只想说“大炮船驶向 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/

相关文章:

java - 如何强制 Firefox 发送隐藏字段?

javascript - 如何在head中使用绝对路径

javascript - 在 Javascript 中运行一个函数,但最后总是返回 'undefined'

javascript - 使用时输出的渲染方式不同(for循环与setInterval,requestAnimationFrame)

function - Haskell 在数据结构中存储函数 - 用例

javascript - 如何将对象的函数指针存储在数组中?

javascript - 在网页之间传递大量数据

Java 在对象引用上调用方法确实会影响调用者

javascript - 如何使用 Protractor 在 e2e 测试中预期元素的动态计数

javascript - 暂停 script.aculo.us 效果