fiddle: https://jsfiddle.net/252jxsjq/1/
how can I show 65 instead of 64.72343432...?
Finally,how can I make the number of clicks equal for all the user?
For example, now if i click 60 times on a button, if I change the pc the times displayed are 0.
jQuery:
var counter = localStorage.getItem('rans') || 0;
$('.redanswer').click(function(){
localStorage.setItem('rans', ++counter);
$( '.bpercent' ).html( counter1 * 100 / (counter1+counter) + "%" );
$( '.rpercent' ).html( counter * 100 / (counter1+counter) + "%" );
});
var counter1 = localStorage.getItem('bans') || 0;
$('.blueanswer').click(function(){
localStorage.setItem('bans', ++counter1);
$( '.rpercent' ).text( counter * 100 / (counter1+counter) + "%" );
$( '.bpercent' ).text( counter1 * 100 / (counter1+counter) + "%" );
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…