2016-05-23 48 views
3

我想警告“运行功能大炮”,然后当我按下确定时,我只想说“大炮船只航行到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> 
+0

试一下没有document.write – 2426021684

回答

1

不给他们相同的变量输出..警报(船),那么文件撰写(船+ .... )。 尝试此代替

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

谢谢。就是这样。 – jjdouble000

+0

欢迎您:-) – matrmawi

2

尝试移除从执行document.write船舶参数和与此替换语句:

文件撰写(“炮船帆关闭以” +数+“度”) ;

然后,你应该能够得到你想要的输出。

* p.s .:如果你在文本编辑器上做这件事,并尝试在浏览器上运行它,可以考虑将标签更改为:。

我希望这有助于!