AjaxComplete()只有一个函数,而不是选择器 [英] AjaxComplete() for only a function, not a selector
本文介绍了AjaxComplete()只有一个函数,而不是选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一个不同的ajaxComplete函数,我需要一个不同的ajaxComplete函数。对于每个点击函数,这是可能的吗?
jQuery(document).ready(function(){
功能,您可以通过测试
var number = 1;
/////////////////////////////////////////// ////////
/ *查看单个项目组合项的按钮* /
jQuery(document).on('click','。cover a,.prev_mimo,.next_mimo' ,function(coverclick){
coverclick.preventDefault();
coverclick.stopPropagation();
coverclick.stopImmediatePropagation();
number ++;
/ *获取链接* /
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 $ b auto:true,
nav:true,
speed:500});
jQuery('。upperdiv')。animate({height:'show',opacity:'show' ,easing:'EaseInBounce'},'slow');
jQuery('。loadmask')。hide();
jQuery('。loadmask-msg')。hide b 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 {
if($(this).hasClass('button1')){
//做一件事
} else if($(this).hasClass('button2')){
// do another
}
});
在这种情况下,您的按钮应该有不同的类来描述他们的操作:
< button class =buttons button1> button1< / button>
< button class =buttons button2> button2< / button>
Hi i have a AjaxComplete function in a js file that fires several clicks for different buttons, but all refered to the same selector.
I need a different ajaxComplete function for every click function, is this possible?
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); }); });
解决方案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>
这篇关于AjaxComplete()只有一个函数,而不是选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文