this would do what you need
nCircleA -1 < 0 ? 0 : --nCircleA
题
So I am working on something, and not quite the best way to approach this.
I have some elements, and basically when a list item is clicked, it adds a value to a div element.
when the other list item is clicked, the siblings value should decrease, but not exceed 0 (ie. -1, -2, -3)
Im just not sure the most logical, easiest way to write that.
percentage = $("#percent1");
percentage2 = $("#percent2");
nCircleA = 0;
nCircleB = 0;
$('ul li.first').on('click', function() {
circle1();
});
$('ul li.second').on('click', function() {
circle2();
});
function circle1() {
percentage.html(++nCircleA);
percentage2.html(--nCircleB);
}
function circle2() {
percentage2.html(++nCircleB);
percentage.html(--nCircleA);
}
circle1();
circle2();
see Fiddle
Thanks
解决方案