重置JavaScript / jQuery中不在表单中的增量值

时间:2015-04-23 22:07:49

标签: javascript jquery

如何重置JavaScript中不在表单中的增量值?

我尝试创建类似于决策树的内容,但要跟踪点击次数,然后根据最高点击次数向他们提供最佳答案。

*奖金

如何根据最高点击次数显示消息?

下面是代码的小提琴链接:

HTML:

<button type="button" onClick="clickME()">Click me</button>
<button type="button" onClick="clickME2()">Click me</button>
<button type="button" onClick="clickME3()">Click me</button>
<button type="button" onClick="clickME4()">Click me</button>
    <p>Clicks1: <a id="clicks">0</a></p>
    <p>Clicks2: <a id="clicks2">0</a></p>
    <p>Clicks3: <a id="clicks3">0</a></p>
    <p>Clicks4: <a id="clicks4">0</a></p>
    <p>Most click is: <a id="clicks5"></a></p>
<button type="reset">Click me</button>

JS:

 var clicks = 0;
 var clicks2 = 0;
 var clicks3 = 0;
 var clicks4 = 0;
    function clickME() {
        clicks += 1;
        clicks2 += 1;
        clicks3 += 1;
        clicks4 += 1;
        document.getElementById("clicks").innerHTML = clicks;
        document.getElementById("clicks2").innerHTML = clicks2;
        document.getElementById("clicks3").innerHTML = clicks3;
        document.getElementById("clicks4").innerHTML = clicks4;
 }
    function clickME2() {
        clicks += 1;
        clicks2 += 1;
        document.getElementById("clicks").innerHTML = clicks;
        document.getElementById("clicks2").innerHTML = clicks2;
 }
    function clickME3() {
        clicks += 1;
        clicks2 += 1;
        clicks3 += 1;
        document.getElementById("clicks").innerHTML = clicks;
        document.getElementById("clicks2").innerHTML = clicks2;
        document.getElementById("clicks3").innerHTML = clicks3
 }
    function clickME4() {
        clicks += 1;
        document.getElementById("clicks").innerHTML = clicks;
 }

http://jsfiddle.net/z66WF/68/

1 个答案:

答案 0 :(得分:0)

http://jsfiddle.net/z66WF/77/ - 回答你的奖金问题

function reset() {
    for(var i=1; i<=4; i++) {
        document.getElementById("clicks"+i).innerHTML = 0;
    }
}