我的分數增加不起作用。兩個問題。得分不遞增javascript
它會自動更新嗎?
或者是我的代碼錯了?
HTML頁面
<script>document.write("Score: " + score);</script>
<table class="widthOneHundredPercent">
<tr>
<td class="tableCellFloat columnOne" valign="top">
<div class="question"><b>Question 1:</b> Who is the youngest in B Media?</div>
<td class="tableCellFloat columnTwo" valign="top">
<div class="answers">
<ol>
<li>
<input type="radio" name="q1" id="q1-a" onclick="unhide(this); scoreIncrement()"/>John
</li>
<li>
<input type="radio" name="q1" id="q1-b" onclick="unhide(this)"/>Paula
</li>
<li>
<input type="radio" name="q1" id="q1-c" onclick="unhide(this)"/>Henal
</li>
<li>
<input type="radio" name="q1" id="q1-d" onclick="unhide(this)"/>Malc
</li>
</ol>
</div>
</td>
</td>
</tr>
<tr>
<td colspan="2" valign="top">
<div id="answerq1a" class="hidden">
<p>Your answer is correct, John is 20.</p>
</div>
</td>
</tr>
<tr>
<td colspan="2" valign="top">
<div id="answerq1b" class="hidden">
<p>Your answer is incorrect, Paula is 31.</p>
</div>
</td>
</tr>
<tr>
<td colspan="2" valign="top">
<div id="answerq1c" class="hidden">
<p>Your answer is incorrect, Henal is 21.</p>
</div>
</td>
</tr>
<tr>
<td colspan="2" valign="top">
<div id="answerq1d" class="hidden">
<p>Your answer is incorrect, Malc is 33.</p>
</div>
</td>
</tr>
</table>
的Javascript
var currentShown = "";
function unhide(rad) {
var id = "answer" + rad.id.replace("-", "");
var answer = document.getElementById(id);
if (answer) {
var current = document.getElementById(currentShown);
if (current) current.className = "hidden";
currentShown = id;
answer.className = "unhidden";
}
}
var score = 0;
function scoreIncrement() {
score++;
}
這種簡單的代碼,但它不會工作,很明顯,我已經寫了錯,但我看不出有什麼不好?
呃,什麼分數增加......在你發佈的代碼中沒有這樣的東西 – scibuff 2012-04-02 16:20:45
哈哈,老實說當我分享時它就在那裏,讓我改變分享鏈接,不知道那裏發生了什麼, 。 – 2012-04-02 16:22:17
http://jsfiddle.net/RfkCw/3/ - 不知道你必須點擊更新,我的壞。新的jsfiddle :) – 2012-04-02 16:23:02