0

嗨,我在一个 js 文件中有一个 AjaxComplete 函数,该函数会为不同的按钮触发多次点击,但都引用了同一个选择器。

我需要为每个点击功能使用不同的 ajaxComplete 功能,这可能吗?

jQuery(document).ready(function(){
var number = 1;
///////////////////////////////////////////////////
 /* The button to see the single portfolio items */
jQuery(document).on('click','.cover a, .prev_mimo, .next_mimo',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');


    return false;

});
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);

            });

      });
4

1 回答 1

2

inside your ajaxComplete() function you can check which was the original button that initiated the ajax call, by testing out $(this).

Try something like this:

 $('.buttons').ajaxComplete(function(){
      if($(this).hasClass('button1')){
         // do one thing
      }else if($(this).hasClass('button2')){
         // do another
      }
 });

in this case, your buttons should have different classes to describe their actions:

<button class="buttons button1">button1</button>
<button class="buttons button2">button2</button>
于 2012-08-01T09:25:22.367 回答