我希望变量根据点击位置增加。然后能够减少它被点击的地方。然而,第一个增量没有存储在z中,所以当我做第二个增量时,它不会与第一个增量相加,只是发布第二个增量。我怎样才能使这个增量工作?下面是代码:基于点击位置的不同值的递增
$(".pesqopcao").click(function() {
var color = $(this).css("background-color");
var z = 0;
if (color == 'rgb(255, 255, 255)' || color == 'white') {
$(this).css("background-color", "blue");
z += (this.id * 1);
document.getElementById("z").innerHTML = z;
} else
if (color == 'rgb(0, 0, 255)' || color == 'blue') {
$(this).css("background-color", "white");
z - (this.id * 1);
document.getElementById("z").innerHTML = z;
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="101" class="pesqopcao">101</div>
<div id="601" class="pesqopcao">601</div>
<div id="901" class="pesqopcao">901</div>
<div id="z"></div>
现在的作品。谢谢 !! – Adato