Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/470.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么我的输出会重复?_Javascript_Function_Parameters_Output_Alert - Fatal编程技术网

Javascript 为什么我的输出会重复?

Javascript 为什么我的输出会重复?,javascript,function,parameters,output,alert,Javascript,Function,Parameters,Output,Alert,我想提醒“正在运行的功能加农炮”,然后当我按下ok时,我希望它只是说“加农炮船航行到14度”,但它会在我的输出中不断打印警报 JS function alertMessage (message) { alert (message); } alertMessage("the Battle has begun"); function alertShip (ship, number) { alert (ship); document.write (ship + "the ship sails o

我想提醒“正在运行的功能加农炮”,然后当我按下ok时,我希望它只是说“加农炮船航行到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(发货+…)。 试试这个

function alertShip (ship, number) {
alert (ship);
document.write ("Cannon ship sails off to " + number + "degrees");

尝试从文档中删除ship参数。编写并用以下内容替换语句:

记录(“炮舰驶向“+数字+”度”)

然后,您应该能够获得所需的输出

*.P.S.:如果你在文本编辑器上这样做,并试图在浏览器上运行,你可以考虑将标签更改为::


我希望这有帮助

不用文档就试试看。谢谢。就是这样。