【发布时间】:2014-04-14 18:40:07
【问题描述】:
代码如下:
<SCRIPT LANGUAGE="Javascript"><!--
function text() {
};
text = new text();
number = 0;
// textArray
text[number++] = "I read the other day some verses written by an eminent painter which were original and not conventional."
text[number++] = "The soul always hears an admonition in such lines, let the subject be what it may."
text[number++] = "The sentiment they instil is of more value than any thought they may contain."
text[number++] = "To believe your own thought, to believe that what is in your private heart is true for all men, that is genius."
increment = Math.floor(Math.random() * number);
document.write(text[increment]);
//--></SCRIPT>
具体是我想要的话:
对你来说是真的
从数组中的第四个文本链接到一些外部网站。
<a> 标签似乎对我不起作用。字符串方法也没有。当然,我是个十足的笨蛋。
【问题讨论】:
-
您有语法错误(未转义的引号)。如果那是 HTML,它也不是封闭引用或封闭标记。您可以编写 Array literal 而不是在此处创建自定义构造函数。最后,
document.write是个坏主意。 -
这是我正在使用的 HTML 的一部分,我从 Javascript Source 借来的。我假设代码是紧密引用/紧密标记的,尽管我太新手无法确定。我也不知道“数组文字”和“document.write”是什么,或者它们是做什么的。 (笨蛋,你看)。这些都是让我原来的问题无法回答的事情吗?
-
你必须从某个地方开始......
标签: javascript arrays hyperlink random-sample