Javascript 为什么我的输出会重复?
我想提醒“正在运行的功能加农炮”,然后当我按下ok时,我希望它只是说“加农炮船航行到14度”,但它会在我的输出中不断打印警报 JSJavascript 为什么我的输出会重复?,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
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.:如果你在文本编辑器上这样做,并试图在浏览器上运行,你可以考虑将标签更改为::
我希望这有帮助 不用文档就试试看。谢谢。就是这样。