Im爲網站提出問題,並希望var reltext中的正確/重試消息爲不同的顏色,例如綠色表示正確,紅色表示錯誤,也可能是每個旁邊有一個小的png。CSS樣式Javascript
有什麼想法?
<form name = "Q1">
<p>A local construction company has purchased 5 brand new diggers. Two of them have a telescopic jib. If a driver chooses a digger to use at random what is the probability it will have a telescopic jib?<br>
0/5
<input name = "rad1" type = "radio" class="radio" onclick = "getAnswer('1a', '1')">
1/5
<input name = "rad1" type = "radio" class="radio" onclick = "getAnswer('1b', '2')">
2/5
<input name = "rad1" type = "radio" class="radio" onclick = "getAnswer('1c', '3')">
3/5
<input name = "rad1" type = "radio" class="radio" onclick = "getAnswer('1d','4')">
<br><br>
</p>
<div id = "para"><div>
</form>
<script type = "text/javascript">
var reltext = [];
reltext[1] = "TRY AGAIN - 0/5 This would mean that there was no diggers with a telescopic jib."
reltext[2] = "TRY AGAIN - 1/5 This would mean that there was only 1 digger with a telescopic jib"
reltext[3] = "CORRECT - 2/5 This would mean that there was 2 diggers with a telescopic jib"
reltext[4] = "TRY AGAIN - 3/5 This would mean that there was 3 diggers with a telescopic jib."
function getAnswer(ans, rel) {
document.getElementById("para").innerHTML = reltext[rel];
if (ans == "1c") {alert ("Correct - Well done!")}
else {alert ("Incorrect - Try again")}
}
</script>
我可能會離開(我沒有在編輯中看到它),但是你原來的問題沒有說你想改變警報框中文本的樣式? – 2012-03-23 12:31:08
起初是的,但我用「reltext」來顯示我的正確/再試圖像,再次感謝您的幫助! – Ma9ic 2012-03-27 13:01:45
將來,將此問題用作不應該做的示例。在事實發生混淆之後,如此激烈地改變你的問題,對那些試圖提供幫助的人來說有點不妥。這很令人困惑,因爲正確的答案不再正確(比如我的回答有6個upvotes),而且這是沒有道理的,因爲你通過改變問題來搶奪人們的正確答案。 – 2012-03-27 13:05:32