2015-02-09 67 views
0

我是编程新手,需要阅读“开始编程”一书。它列出了下面的代码写在网站上的基本路线:如何在Javascript中编写基本行

<!DOCTYPE html> 
<html> 
<body> 

<h1>This is a Test</h1> 

<script> 

document.write("<p>I like to code</p>"); 
document.write("<p>I will succeed at coding</p>"); 
</script> 

</body> 
</html> 

不幸的是,线

document.write("<p>I like to code</p>"); 

不给的“我喜欢码”写在网站上所需的输出。

这应该怎么写才能得到这个输出?

+2

和它给了什么结果? – 2015-02-09 02:33:22

+0

它适用于Firefox,Chrome和Opera。显示所有三行文字。您的浏览器可能禁用JavaScript吗? – Mars 2015-02-09 02:37:06

+0

您是否想印刷“

我喜欢代码

”而不是“我喜欢编码”? – 2015-02-09 02:40:01

回答

2

您的代码似乎运行良好。尝试将您的HTML文件更新为此:

<!DOCTYPE html> 
<html> 
    <body> 
     <h1>This is a Test</h1> 
     <script> 
      document.write("<p>I like to code</p>"); 
      document.write("<p>I will succeed at coding</p>"); 
     </script> 
     <noscript> 
      Javascript is disabled! 
     </noscript> 
    </body> 
</html> 

并且如果您看到“Javascript is disabled!”那么你需要让你的浏览器使用JavaScript。

祝你好运:)

1

<!DOCTYPE html> 
 
<html> 
 
<body> 
 

 
<h1>This is a Test</h1> 
 

 
<script> 
 

 
document.write("<p>I like to code</p>"); 
 
document.write("<p>I will succeed at coding</p>"); 
 
</script> 
 

 
</body> 
 
</html>

似乎运行正常。复制粘贴相同的代码