gpt4 book ai didi

javascript - 如何简化这个 Javascript 文件

转载 作者:行者123 更新时间:2023-12-02 06:00:26 26 4
gpt4 key购买 nike

我有一个这样的脚本:

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

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

最佳答案

这样会更好:

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."
]

如果你真的想的话,你可以把它放在一个单独的脚本中。除此之外,没有任何“简单”的方法来改进脚本。

编辑:

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

<script src="whatever.js"></script>

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

关于javascript - 如何简化这个 Javascript 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27141522/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com