我希望它显示骰子图像但没有输出?怎么了?我从 1-6 中选择一个随机数,它会显示骰子的面。那么它应该,但它不工作。我还想在其他地方显示图像而不是替换按钮。你是怎样做的?
<html>
<head><title>DiceBoy</title>
</head>
<body>
<script>
function getRandom(){
var RandomNumber1 = Math.floor(Math.random() * 6) + 1;
var RandomNumber2 = Math.floor(Math.random() * 6) + 1;
if(RandomNumber1 == 1) document.write('<img src="dice1.png">');
else if(RandomNumber1 == 2) document.write('<img src="dice2.png">');
else if(RandomNumber1 == 3) document.write('<img src="dice3.png">');
else if(RandomNumber1 == 4) document.write('<img src="dice4.png">');
else if(RandomNumber1 == 5) document.write('<img src="dice5.png">');
else var document.write('<img src="dice6.png">');
}
</script>
<input type="button" value="Throw Dices" onClick="getRandom();">