-1

javascriptは初めてですが、C ++ C#VBを実行しました。しかし、このjavascriptの本は理解するのが難しいです、それは見るべき完全なコードを行使するだけです。とにかく私は簡単なプロジェクトをやっていますが、どこが間違っているのかわかりません。CDATAは、私が間違っていると私が信じているところです。これは私の2番目のプロジェクトであり、最初のプロジェクトは簡単でした。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>

それは非常に単純なプロジェクトであり、どこが間違っているのかを理解するのに助けが必要です。前もって感謝します

4

4 に答える 4

0

ローカルで実行すると、JavaScript エラー コンソールにより、問題がどこにあるかが非常に明確になります。行番号も表示されます。

document.write("<p>The largest island
in the world is " + island1Name...

JavaScript 文字列の途中で改行することはできません。

document.write("<p>The largest island in the world is " + island1Name...

動作します。それらをすべて修正し、すべての主要なブラウザーで利用可能な開発ツールを使い始める必要があります。

于 2013-02-13T17:40:31.080 に答える
0

問題はストリングラインを壊すことから来ていると思います

それ以外の

document.write("<p>The largest island
in the world is " + island1Name

試す

document.write("<p>The largest island" 
+ "in the world is " + island1Name
于 2013-02-13T17:40:37.660 に答える
0

あなたの問題は、このような複数の行文字列が JavaScript で許可されていないことです:

document.write("<p>The second largest island
in the world is " + island2Name

間違った場所にあるこれらの新しい行を削除すると、コードは機能します。その行は次のようになります。

document.write("<p>The second largest island in the world is " + island2Name

例: http://jsbin.com/igowel/1/edit

JavaScript を引き続き使用するには、コンソールと開発者ツールの使用に慣れてください。Chrome については、この Q&A をご覧ください: Google Chrome で JavaScript コンソールを使用するにはどうすればよいですか?

于 2013-02-13T17:40:40.767 に答える
0

あなたの問題は改行だと思います。あなたのコード:

document.write("<p>The largest island
in the world is " + island1Name
+ " with " + island1Size + " miles.</p>");

する必要があります:

document.write("<p>The largest island in the world is " + island1Name
+ " with " + island1Size + " miles.</p>");

行で文字列を開始し、同じ行で終了しない場合、改行エラーが発生します。また、スクリプトをデバッグできる firebug と一緒に開発に firefox を使用することをお勧めします。

于 2013-02-13T17:43:41.857 に答える