2012-02-20 15 views
0

私はこのHTMLとjavascriptを今や1〜2時間手抜きしていますが、なぜ動作しないのかわかりません。私は自分自身でhtml、css、javascriptを学ぼうとしていました...しかし、私はEclipseが私のものをとてもうまくデバッグしているとは思いません...何が起こっていますか?このHTML/Javascript/CSSでランダムな文字列を生成していますか?

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> 
<head> 
<style type="text/css"> 
a:link {color:#FF0000;} /* unvisited link */ 
a:visited {color:#00FF00;} /* visited link */ 
a:hover {color:#FF00FF;} /* mouse over link */ 
a:active {color:#0000FF;} /* selected link */ 
</style> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<title>Catlard.com</title> 

<link rel=StyleSheet href="styles/menuStyle.css" type="text/css"/> 

<script type="text/javascript"> 

function RandomQuote() 
{ 
    var quotes= new Array(); 
    quotes[0] = "...believes it may be useful in a time of need." 
    quotes[1] = "...knows you have a problem, but accepts you anyway." 
    quotes[2] = "...believes the aliens were involved at Oak Island." 
    quotes[3] = "...demands to know the location of your hidden rebel base!" 
    quotes[4] = "...SAW you take the cookie from the cookie jar." 
    return quotes[Math.floor(Math.random() * 4.99); 
} 

</script> 

</head> 
<body> 

<div id="framecontent"> 
<div class="innertube"> 
<h1>CSS Top Frame Layout</h1> 
<span style="font-family : Courier;color: #000000;"> 
<a href="resume.html"> Resume </a> 
<a href="http://catlard.blogspot.com"> Blog </a> 
<a href="pixelating.html"> Arts n' Farts</a> 
<a href="contact.html"> Contact </a> 
<a href="typing.html"> Games </a> 
</span> 
</div> 
</div> 


<div id="maincontent"> 
<div class="innertube"> 

document.write(RandomQuote()); 
<p style="text-align: center">Blah blah blah </p> 
</div> 
</div> 

</body> 
</html> 
+0

これを実行すると何が起こるかはわかりません。何が問題ですか? – Beska

+0

ああ、申し訳ありません。私はそれを実行すると、私はどこに関数を呼び出すブラウザに何も表示されません。 – Catlard

+0

*あなたのコードを*呼び出すことはないからです。テキスト形式です。別のスクリプトタグに入れてみてください。 rの欠如のために-1 –

答えて

1

返品見積もり行に誤りがあります。それは))]を閉じる必要があります。そうではない。

また、引用符[n]の各行はセミコロンで終わる必要があります。

そして、scriptタグ内にdocument.write()を置く必要があります。

+0

はいちょっと欠けてth]最後にオフ – Dampsquid

+0

@Dampsquidは意味を明確にするために編集されています。ありがとう。 – Jordan

+0

ああ、これはまさに正しいです。私はこれらすべてのことをしました、そして今、それは働いています。私はすべての構文エラーをお詫びします。私は非常に良いIDEを持っていません - 私は現時点でJavascriptのEclipseを使用しています。 OSX 32ビットの初心者向けの提案はありますか? – Catlard

1

"document.write"行は<script>領域にある必要があります。返信行に "]"括弧もありません。

+0

ありがとう、ありがとう。 – Catlard

0

コードを少しはっきりとチェックする必要があります。おそらく、SciTeのような構文強調表示プログラミングエディタを使用してください。あなたは明示的には私たちにあなたが持っている問題を教えてくれなかったにもかかわらず

(ちょうどそのが動作していないと述べた)私に飛び出しまず最初に、このラインである:あなたが終わるを忘れてしまった

return quotes[Math.floor(Math.random() * 4.99); 

]に配列。

+0

ああ、そうです。どうもありがとうございました。私は日食の代わりにSciTeをチェックします。チェリオ! – Catlard

0

returnコマンドに「終了がありません」というメッセージが表示されます。

+0

ありがとう!これは、とりわけ大きな問題でした。 – Catlard

0

2物事:

return quotes[Math.floor(Math.random() * 4.99)]; 

あなたの引用符の配列の終了タグを逃しています。

<script language="javascript" type="text/javascript"> 
    document.write(RandomQuote()); 
</script> 

あなたのjavascriptのは、スクリプトタグ内にラップする必要がある、またはそうでなければ、単にHTMLとしてレンダリングされます。

関連する問題