我面临一个挑战,我需要改变全球价值。请参阅下面的代码,每当用户单击#first时,它将计算时间并存储在服务器端。但是,我希望实现这一点,如果我点击第二个,全局值变为1.因此,当我再次点击#first时,它再次从1开始。我怎么能实现这一点,欣赏?
var count=1;//global value
$('#first').on('click',function(){
count++
});
$('#second').on('click',function(){
//count--(minus)?? make the global value
//become 1 no matter how many time I have clicked #first
});
答案 0 :(得分:3)
Javascript
var count=1;//global value
$('#first').on('click',function(){
count++ ;
});
$('#second').on('click',function(){
count=1; //make the global value become 1 no matter how many time I have clicked #first
});