2012-08-01 73 views
0

你好,我使用此代码:ñ点击,n次重复的点击功能,为什么呢?

jQuery(document).ready(function(){ 
var number = 1; 
/////////////////////////////////////////////////// 
    /* The button to see the single portfolio items */ 
jQuery('.cover a').unbind("click").click(function (coverclick){ 

    coverclick.preventDefault(); 
    coverclick.stopPropagation(); 
    coverclick.stopImmediatePropagation(); 
    number ++; 
    /* Get the link */ 
    var coverlink = jQuery(this).attr('href'); 
    jQuery('.loadmask').show(); 
    jQuery('.loadmask-msg').show(); 
    jQuery('.upperdiv').animate({height : 'hide', opacity : 'hide', easing: 'EaseOutBounce'},'slow', function(){          jQuery('.upperdiv').html('');}); 
    jQuery('.upperdiv').load(coverlink+' .loading_div'); 
    jQuery('.upperdiv').ajaxComplete(function() { 
     var slideClass = 'all_project_images' + number; 
     var dentroClass = '.' + slideClass; 
     jQuery('html,body').stop().animate({ 
        scrollTop: jQuery(this).offset().top}, 
        'slow'); 
     jQuery('.post_nav_portfolio').show(); 
     jQuery('.slideshow ul').removeClass().addClass(slideClass); 
     jQuery(dentroClass).stop(false,true).responsiveSlides({ 
        auto: true, 
        nav: true, 
        speed: 500}); 
     jQuery('.upperdiv').animate({height : 'show', opacity : 'show', easing: 'EaseInBounce'},'slow'); 
     jQuery('.loadmask').hide(); 
     jQuery('.loadmask-msg').hide(); 
     jQuery('.cover').hover(function(){ 
       jQuery(this).children('.mimo_portfolio_image').stop().animate({opacity : 0.5},'fast'); 
        }, function(){ 
       jQuery(this).children('.mimo_portfolio_image').stop().animate({opacity : 1},'fast'); 
        }); 
     jQuery("a[rel^='prettyPhoto']").prettyPhoto(); 
     jQuery('.slideshow').hover(function(){ 
       jQuery(this).children('.rslides_nav').show('slow'); 
       }, function(){ 
       jQuery(this).children('.rslides_nav').hide('slow'); 
      }); 
      console.log(dentroClass); 

      }); 

    return false; 

}); 

    }); 

加载和显示组合的项目,它的负载和伟大工程,但我有一个问题复制与 的console.log(dentroClass);

我可以看到,首先点击它记录1次变量,第二次点击记录2次,3次点击记录3次,好所有功能重复点击次数,如果是第五次点击它重复5次功能。

我一直在on();和OFF();和bind();解除绑定();但没有任何工作。

+1

一个快速protip:如果你没有使用任何其他外部库使用$,你应该参考与$的jQuery。例如:'$(“ loadmask”)显示();' – Rodik 2012-08-01 08:48:49

+0

谢谢你,我已经做到了,但每次我指一样,没有什么时间工程..¿ – 2012-08-01 09:10:32

回答

2

我猜你每次点击时都会绑定新的ajaxCompletehover处理程序。

您应该将所有这些绑定移到点击功能之外。 (以便它们只能运行一次。)

或在每次点击开始时解除所有操作。

+0

谢谢!它完美的作品!我有我已经分居了,如果你想在这里只是为了给新分一个小问题,以及系统doesn't让我发布更多的问题,现在:嗨,我havan AjaxComplete功能将触发不同的按钮点击几个JS文件,但所有refered相同的选择。 我需要为每次点击的功能不同ajaxComplete功能,这可能吗? – 2012-08-01 09:02:22

+0

系统告诉我等待20分钟才能提出问题... – 2012-08-01 09:07:26

+0

在这里您有问题:[link](http://stackoverflow.com/questions/11756211/ajaxcomplete-for-only-a-function-not -a选择器) – 2012-08-01 09:20:22