AjaxComplete()仅用于函数,而不是选择器

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

我需要为每个点击function使用不同的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); }); }); 

在你的ajaxComplete()函数中你可以通过测试$(this)来检查哪个是启动ajax调用的原始按钮。

尝试这样的事情:

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

在这种情况下,您的按钮应该有不同的类来描述他们的操作: