如何简化这个 Javascript 文件

Rac*_*cer 2 javascript php file

我有一个像这样的脚本:

<span>Famous Quote:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="JavaScript">
var Quotation=new Array() // do not change this!
Quotation[0] = "Time is of the essence! Comb your hair.";
Quotation[1] = "Sanity is a golden apple with no shoelaces.";
Quotation[2] = "Repent! The end is coming, $9.95 at Amazon.";
Quotation[3] = "Honesty blurts where deception sneezes.";
Quotation[4] = "Pastry satisfies where art is unavailable.";
Quotation[5] = "Delete not, lest you, too, be deleted.";
Quotation[6] = "O! Youth! What a pain in the backside.";
Quotation[7] = "Wishes are like goldfish with propellors.";
Quotation[8] = "Love the river's \"beauty\", but live on a hill.";
Quotation[9] = "Invention is the mother of too many useless toys.";
Quotation[10] = "Things are only impossible until they're not.";
var Q = Quotation.length;
var whichQuotation=Math.round(Math.random()*(Q-1));
function showQuotation(){document.write(Quotation[whichQuotation]);}
showQuotation();
</script>
Run Code Online (Sandbox Code Playgroud)

如何将引用放在自己的文件中,而不是源代码中?这是一个示例:http://mydomain.go/quote.js

Jay*_*rby 5

这样会更好:

var Quotation=
[
    "Time is of the essence! Comb your hair.",
    "Sanity is a golden apple with no shoelaces.",
    "Repent! The end is coming, $9.95 at Amazon.",
    "Honesty blurts where deception sneezes.",
    "Pastry satisfies where art is unavailable.",
    "Delete not, lest you, too, be deleted.",
    "O! Youth! What a pain in the backside.",
    "Wishes are like goldfish with propellors.",
    "Love the river's \"beauty\", but live on a hill.",
    "Invention is the mother of too many useless toys.",
    "Things are only impossible until they're not."
]
Run Code Online (Sandbox Code Playgroud)

如果您确实愿意,可以将其放入单独的脚本中。除此之外,没有任何“简单”的方法来改进脚本。

编辑:

将其放在单独的文件中,然后添加脚本标签:

<script src="whatever.js"></script>
Run Code Online (Sandbox Code Playgroud)

然后您将可以访问Quotation主文件。