用这个HTML/Javascript/CSS生成一个随机字符串

Generating a random string with this HTML/Javascript/CSS?

本文关键字:一个 随机 字符串 HTML Javascript CSS      更新时间:2023-09-26

我已经摆弄这个HTML和javascript一两个小时了。。。我不明白为什么它不起作用。我一直在尝试自己学习html、css和javascript。。。但我不认为Eclipse对我的东西进行了很好的调试。。。发生了什么事?

<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>

返回引号行出现错误。应以)结尾];不是);

此外,您的每一行引号[n]都应该以分号结尾。

并且,您应该在script标记中包含document.write()。

您的"document.write"行需要位于<script>区域中。您还缺少返回线上的"]"括号。

您需要更清楚地检查代码。也许可以使用诸如SciTe之类的语法高亮编程编辑器。

尽管你没有明确告诉我们你的问题(只是说它不起作用),但我想到的第一件事是:

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

您忘记了数组上的结尾]

您在return命令中缺少结尾]。

两件事:

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

您的引号数组缺少结束标记。

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

您的javascript必须封装在该脚本标记中,否则它将被呈现为HTML。