0
我一直在试图找出如何在随机数匹配后每次点击按钮时执行增量或不匹配。jquery匹配随机数后增加分数
基本上,如果数字匹配,匹配的计数器会上升。数字不匹配也是一样。
但目前,柜台只会上涨一次。
的jQuery:
$(document).ready(function(){
var a;
var b;
display();
displayInt();
function displayInt(){
var disInt;
disInt = setInterval(display, 2000);
}
function display() {
a = Math.floor((Math.random()*3)+1);
$("#number1").html(a);
b = Math.floor((Math.random()*3)+1);
$("#number2").html(b);
}
function addScore(){
var correct;
var wrong;
correct=0;
wrong=0;
if (a == b){
correct++;
$("#correctScore").html(correct);
}else{
wrong++;
$("#wrongScore").html(wrong);
}
}
$('input[type="button"]').click(function() {
a = $("#number2").html();
b = $("#number1").html();
addScore();
});
});
我现在感觉很愚蠢的,太感谢你了! – Yatlax
没问题!请标记最能回答您问题的答案。 – user707727