gpt4 book ai didi

javascript - 尝试设置随机文本。我的代码有什么问题?

转载 作者:行者123 更新时间:2023-11-29 16:18:32 25 4
gpt4 key购买 nike

我正在尝试设置一些内容,基本上是从一组预定义的短语中进行选择,并将其显示为我页面上的副标题。我在这里做错了什么?

    <html>
<head>
<script type="text/javascript">
function RandomQuote()
{
var quotes= new Array();
quotes[0] = 'Home of Fall!'
quotes[1] = 'At Least This is Something!'
quotes[2] = 'Javascript!'
quotes[3] = 'Railroads at Last!'
quotes[4] = 'Better than Wikipedia'
quotes[5] = 'Now with Scorpions!'
quotes[6] = 'Irrelevant Stuff!'
quotes[7] = 'Fall is here!'
quotes[8] = 'That moment when Image-908329490283094.jpg'
quotes[9] = 'With Added Roundness!'
quotes[10] = 'Bacon!'
quotes[11] = 'Try Out WinterNstuff!'
quotes[12] = 'Try Out SpringNstuff!'
quotes[13] = 'Try Out SummerNstuff!'
quotes[14] = 'all html is lowercase!'
quotes[15] = '<div id=''youWishYouCouldReadThis''>InsertCodeHere</div>'
quotes[16] = 'In Remembrance of the soldiers who died in the Iranian War'
quotes[17] = 'Leaf Me Alone!'
quotes[18] = 'Pumpkins Were So 2011.'
quotes[19] = 'This Does not Count as a Random String'
quotes[20] = 'With Added Content Generation!'

return quotes[Math.floor((Math.random() * 19.9999))];
}
</script>
<title></title>
</head>
<body>
<div id="container">
<div id="header">
<table style="background-color:blue">
String:
<script type="text/javascript">document.write(RandomQuote());</script>
</table>
</body>
</div>
</div>

作为后续,有没有办法配置一个标题来做同样的事情,随机生成字符串?

最佳答案

您需要在引号 [15] 中转义引号。这是一个工作 fiddle http://jsfiddle.net/ranjith19/HCCSW/

function RandomQuote()
{
var quotes= new Array();
quotes[0] = 'Home of Fall!'
quotes[1] = 'At Least This is Something!'
quotes[2] = 'Javascript!'
quotes[3] = 'Railroads at Last!'
quotes[4] = 'Better than Wikipedia'
quotes[5] = 'Now with Scorpions!'
quotes[6] = 'Irrelevant Stuff!'
quotes[7] = 'Fall is here!'
quotes[8] = 'That moment when Image-908329490283094.jpg'
quotes[9] = 'With Added Roundness!'
quotes[10] = 'Bacon!'
quotes[11] = 'Try Out WinterNstuff!'
quotes[12] = 'Try Out SpringNstuff!'
quotes[13] = 'Try Out SummerNstuff!'
quotes[14] = 'all html is lowercase!'
quotes[15] = '<div id=\'youWishYouCouldReadThis\'>InsertCodeHere</div>'
quotes[16] = 'In Remembrance of the soldiers who died in the Iranian War'
quotes[17] = 'Leaf Me Alone!'
quotes[18] = 'Pumpkins Were So 2011.'
quotes[19] = 'This Does not Count as a Random String'
quotes[20] = 'With Added Content Generation!'

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

关于javascript - 尝试设置随机文本。我的代码有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13005122/

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