1
对不起,我的格式很烂。每次单击按钮时我都会显示一个随机引号,每次单击它时都会显示一个不同的引号。我需要添加一个document.write或其他任何地方?我确定这里和那里有一堆错误,但我只想从函数中返回一个随机引用。Javascript函数不显示随机消息
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Random quote</title>
<style>
body {
background-color: #fff;
font-family: sans-serif;
color: #28315C;
}
h1 {
text-align: center;
}
button {
border-color: #000;
background-color: #88D0FE;
color: #000;
font-size: 20px;
}
</style>
</head>
<body>
<script>
var quotes = ['this is fortune 1',
'this is fortune 2',
'this is fortune 3',
'this is fortune 4',
'this is fortune 5',
'this is fortune 6',
'this is fortune 7',
];
function newQuote(){
var randomNumber = Math.floor(math.random() * (quotes.length));
document.getElementById('quoteDisplay').innerHTML = quotes[randomNumber];
}
</script>
</body>
<div id="quoteDisplay">
</div>
<button onclick="newQuote()">New Quote</button>
</html>
变化'Math.floor(的Math.random()''到Math.floor(的Math.random()' –
调试步骤1 - 浏览器** **开发工具控制台(F12) - 你的问题是'数学'!=='数学' –