Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.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中遇到CDATA问题 我对JavaScript有了新的认识,我已经做了C++ C++ VB.但这本javascript书很难理解,它只是练习,没有完整的代码可看。不管怎么说,我正在做一个简单的项目,但我不明白我错在哪里。CDATA是我认为我出错的地方。这是我的第二个项目,第一个项目很简单。直到CDATA和Var出现,我才陷入困境。我知道这段代码已经过时了,但我正在按照这本书学习基本的JS并逐步提高。代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Largest Islands</title> <meta http-equiv="content-type" content="text/html; charset=iso- 8859-1" /> </head> <body> <h1>Largest Islands</h1> <script type="text/javascript"> /* <![CDATA[ */ var island1Name = "Greenland"; var island2Name = "New Guinea"; var island3Name = "Borneo"; var island4Name = "Madagascar"; var island5Name = "Baffin"; var island1Size = 2175600; var island2Size = 790000; var island3Size = 737000; var island4Size = 587000; var island5Size = 507000; document.write("<p>The largest island in the world is " + island1Name + " with " + island1Size + " miles.</p>"); document.write("<p>The second largest island in the world is " + island2Name + " with " + island2Size + " miles.</p>"); document.write("<p>The third largest island in the world is " + island3Name + " with " + island3Size + " miles.</p>"); document.write("<p>The fourth largest island in the world is " + island4Name + " with " + island4Size + " miles.</p>"); document.write("<p>The fifth largest island in the world is " + island5Name + " with " + island5Size + " miles.</p>"); /* ]]> */ </script> </body> </html> 最大的岛屿 最大的岛屿 /* */_Javascript_Html_Css - Fatal编程技术网

我在javascript中遇到CDATA问题 我对JavaScript有了新的认识,我已经做了C++ C++ VB.但这本javascript书很难理解,它只是练习,没有完整的代码可看。不管怎么说,我正在做一个简单的项目,但我不明白我错在哪里。CDATA是我认为我出错的地方。这是我的第二个项目,第一个项目很简单。直到CDATA和Var出现,我才陷入困境。我知道这段代码已经过时了,但我正在按照这本书学习基本的JS并逐步提高。代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Largest Islands</title> <meta http-equiv="content-type" content="text/html; charset=iso- 8859-1" /> </head> <body> <h1>Largest Islands</h1> <script type="text/javascript"> /* <![CDATA[ */ var island1Name = "Greenland"; var island2Name = "New Guinea"; var island3Name = "Borneo"; var island4Name = "Madagascar"; var island5Name = "Baffin"; var island1Size = 2175600; var island2Size = 790000; var island3Size = 737000; var island4Size = 587000; var island5Size = 507000; document.write("<p>The largest island in the world is " + island1Name + " with " + island1Size + " miles.</p>"); document.write("<p>The second largest island in the world is " + island2Name + " with " + island2Size + " miles.</p>"); document.write("<p>The third largest island in the world is " + island3Name + " with " + island3Size + " miles.</p>"); document.write("<p>The fourth largest island in the world is " + island4Name + " with " + island4Size + " miles.</p>"); document.write("<p>The fifth largest island in the world is " + island5Name + " with " + island5Size + " miles.</p>"); /* ]]> */ </script> </body> </html> 最大的岛屿 最大的岛屿 /* */

我在javascript中遇到CDATA问题 我对JavaScript有了新的认识,我已经做了C++ C++ VB.但这本javascript书很难理解,它只是练习,没有完整的代码可看。不管怎么说,我正在做一个简单的项目,但我不明白我错在哪里。CDATA是我认为我出错的地方。这是我的第二个项目,第一个项目很简单。直到CDATA和Var出现,我才陷入困境。我知道这段代码已经过时了,但我正在按照这本书学习基本的JS并逐步提高。代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Largest Islands</title> <meta http-equiv="content-type" content="text/html; charset=iso- 8859-1" /> </head> <body> <h1>Largest Islands</h1> <script type="text/javascript"> /* <![CDATA[ */ var island1Name = "Greenland"; var island2Name = "New Guinea"; var island3Name = "Borneo"; var island4Name = "Madagascar"; var island5Name = "Baffin"; var island1Size = 2175600; var island2Size = 790000; var island3Size = 737000; var island4Size = 587000; var island5Size = 507000; document.write("<p>The largest island in the world is " + island1Name + " with " + island1Size + " miles.</p>"); document.write("<p>The second largest island in the world is " + island2Name + " with " + island2Size + " miles.</p>"); document.write("<p>The third largest island in the world is " + island3Name + " with " + island3Size + " miles.</p>"); document.write("<p>The fourth largest island in the world is " + island4Name + " with " + island4Size + " miles.</p>"); document.write("<p>The fifth largest island in the world is " + island5Name + " with " + island5Size + " miles.</p>"); /* ]]> */ </script> </body> </html> 最大的岛屿 最大的岛屿 /* */,javascript,html,css,Javascript,Html,Css,这是一个非常简单的项目,我只是需要一些帮助,找出我的错误。提前感谢您在本地运行它,JavaScript错误控制台可以非常清楚地指出问题所在。它甚至会给你行号 document.write("<p>The largest island in the world is " + island1Name... document.write(“最大的岛屿 世界上有“+island1Name…”。。。 在JavaScript字符串中间不能有行中断。 document.write("<p

这是一个非常简单的项目,我只是需要一些帮助,找出我的错误。提前感谢您

在本地运行它,JavaScript错误控制台可以非常清楚地指出问题所在。它甚至会给你行号

document.write("<p>The largest island
in the world is " + island1Name...
document.write(“最大的岛屿
世界上有“+island1Name…”。。。

在JavaScript字符串中间不能有行中断。

document.write("<p>The largest island in the world is " + island1Name...
document.write(“世界上最大的岛屿是”+island1Name。。。

工作正常。您需要修复所有这些问题,并开始在每个主要浏览器中使用可用的开发工具。

我认为问题来自断开字符串线

而不是

document.write("<p>The largest island
in the world is " + island1Name
document.write(“最大的岛屿
世界上有“+岛屿1”的名字
试一试

document.write(“最大的岛屿”
+“在世界上是”+岛屿1名称

您的问题是,JavaScript中不允许使用这样的多行字符串:

document.write("<p>The second largest island
in the world is " + island2Name
document.write(“第二大岛
世界上有“+island2Name”
如果您在错误的位置删除了这些新行,代码就会正常工作。该行现在看起来如下所示:

document.write("<p>The second largest island in the world is " + island2Name
document.write(“世界第二大岛是”+island2Name
例如:


要继续使用JavaScript,请习惯使用控制台和开发人员工具。对于Chrome,请看以下问答:

我认为您的问题在于这里的换行符。 您的代码:

document.write("<p>The largest island
in the world is " + island1Name
+ " with " + island1Size + " miles.</p>");
document.write(“最大的岛屿
世界上有“+岛屿1”的名字
+“带“+岛1大小+”英里。

”;
应该是:

document.write("<p>The largest island in the world is " + island1Name
+ " with " + island1Size + " miles.</p>");
document.write(“世界上最大的岛屿是”+island1Name
+“带“+岛1大小+”英里。

”;
如果在一行中开始一个字符串,但没有在同一行上结束,则会导致换行抛出错误。
此外,我建议您使用firefox和firebug进行开发,在firebug中您可以调试脚本。

不,CDATA并不是您出错的地方。它应该做什么?它做得不对吗?有什么错误吗?那么什么不起作用呢?谢谢。这很奇怪,因为我的书告诉我要打破CDATA。老实说,它看起来像一个r很老的书。虽然从香草JavaScript开始很好,但像jQuery这样的入门真的很方便。如果这本书已经有2-3年的历史了,你可能会想要一本像jQuery这样的最新的书(实际上,我还是建议这样)。
document.write("<p>The largest island in the world is " + island1Name
+ " with " + island1Size + " miles.</p>");