我有小问题。我正在学习 javascript,我想使用switch
.
所以我创建了这个html代码
<body onload="rndqu()">
<div id="head"> <a href="index.html">Mira's place<a><br>
<h2>“<span id="quote"></span>”</h2>
</div>
</body>
并使用了这个 Javascript
var qu;
var slogan;
function rndqu(n){
var random = function(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
};
qu = random(1, 3);
}
switch(qu){
case 1:
slogan = "Here is the 1";
break;
case 2:
slogan = "Here is the 2";
break;
case 3:
slogan = "Woah";
break;
default:
slogan = "Really?";
}
document.getElementById("quote").innerHTML = slogan;
我不明白为什么它不起作用。有人能帮我吗?谢谢!这是它的jsfiddle http://jsfiddle.net/NX3cz/