这是代码;javascript
function Roll()
// Results: displays a randomly selected image of a 6-sided die
{
var roll;
roll = RandomInt(1, 6);
if (roll == 1) {
document.getElementById("die").src =
"die1.gif";
document.write("<center><p><a href='bad.html'> Enter </a></p></center>");
}
else if (roll == 2) {
document.getElementById("die").src =
"die2.gif";
document.write("<center><p><a href='good.html'> Enter </a></p></center>");
}
else if (roll == 3) {
document.getElementById("die").src =
"die3.gif";
document.write("<center><p><a href='bad.html'> Enter </a></p></center>");
}
else if (roll == 4) {
document.getElementById("die").src =
"die4.gif";
document.write("<center><p><a href='good.html'> Enter </a></p></center>");
}
else if (roll == 5) {
document.getElementById("die").src =
"die5.gif";
document.write("<center><p><a href='bad.html'> Enter </a></p></center>");
}
else {
document.getElementById("die").src =
"die6.gif";
document.write("<center><p><a href='good.html'> Enter </a></p></center>");
}
}
这里是 Jsfiddle http://jsfiddle.net/seymorevenue/TcNF7/(虽然 document.write 似乎在那里不起作用,并且骰子图像也没有出现)我认为我并不真正理解文档。写语句,有没有更好的方法?我想要做的就是掷骰子并根据结果显示一个链接。谢谢你的帮助