这是因为选择器“body,html”,它注册了两个单击事件处理程序,一个用于元素body
,另一个用于html
元素。因此,由于事件传播,任何单击都会导致事件处理程序被调用。这将导致a
增加 2,因为 click 事件处理程序被调用了两次。
然后再次animate
在每个单击函数中调用 html 和 body 元素,这将导致该complete
函数在每次单击中被调用两次。因此,每次点击4
都会添加总数a
尝试
$('body').click(function(){
$(this).animate({
scrollTop: $(test[a]).offset().top
},{ duration: 100, queue: false, complete: function(){
$(prvL).css({"background-color":"#fffeec", "border":"0px solid #ff6600", "margin-left":"0px"});
$(prvO).css({"background-color":"#fffeec", "border":"0px solid #ff6600", "margin-left":"0px"});
$(prvA).css({"background-color":"#fffeec", "border":"0px solid #ff6600", "margin-left":"0px"});
$(prvD).css({"background-color":"#fffeec", "border":"0px solid #ff6600", "margin-left":"0px"});
$(prvI).css({"background-color":"#fffeec", "border":"0px solid #ff6600", "margin-left":"0px"});
$(prvN).css({"background-color":"#fffeec", "border":"0px solid #ff6600", "margin-left":"0px"});
$(prvG).css({"background-color":"#fffeec", "border":"0px solid #ff6600", "margin-left":"0px"});
$(somearr[a]).css({"background-color":"#fff", "border":"5px solid #ff6600", "margin-left":"-5px"});
a++; //decided to impliment 4 times.
console.log(a);
if(a===7){a = 0; $(filler_six).hide(); $(filler).show();}
clearDiv();
}}); //end of animation
}); //end of click function
// Clearing The Div's
对于火狐
$('html, body').click(function(e){
e.stopPropagation();
$('body').animate({
scrollTop: $(test[a]).offset().top
},{ duration: 100, queue: false, complete: function(){
$(prvL).css({"background-color":"#fffeec", "border":"0px solid #ff6600", "margin-left":"0px"});
$(prvO).css({"background-color":"#fffeec", "border":"0px solid #ff6600", "margin-left":"0px"});
$(prvA).css({"background-color":"#fffeec", "border":"0px solid #ff6600", "margin-left":"0px"});
$(prvD).css({"background-color":"#fffeec", "border":"0px solid #ff6600", "margin-left":"0px"});
$(prvI).css({"background-color":"#fffeec", "border":"0px solid #ff6600", "margin-left":"0px"});
$(prvN).css({"background-color":"#fffeec", "border":"0px solid #ff6600", "margin-left":"0px"});
$(prvG).css({"background-color":"#fffeec", "border":"0px solid #ff6600", "margin-left":"0px"});
$(somearr[a]).css({"background-color":"#fff", "border":"5px solid #ff6600", "margin-left":"-5px"});
a++; //decided to impliment 4 times.
console.log(a);
if(a===7){a = 0; $(filler_six).hide(); $(filler).show();}
clearDiv();
}}); //end of animation
}); //end of click function
// Clearing The Div's