[英]Run jquery function after another function completes
I want to execute a custom Jquery function after another custom function completes I use timer to func2. 我想在另一个自定义函数完成后执行自定义Jquery函数,我使用timer来func2。 It is not correctly solution.
这不是正确的解决方案。 How can I write it؟
我怎么写?
function fun1() { $('#sideNavBox .root.static > li.static').each(function(){ if($(this).find('ul').length){ $(this).addClass('remove');} $('#sideNavBox .root.static > li.remove > a').replaceWith(function(){ return $('<span class="additional-background ms-navedit-flyoutArrow">'+$(this).html()+'</span>' ); }); }); }; setTimeout( function fun2() { $('#sideNavBox .root.static > li.father > span').removeClass('additional-background ms-navedit-flyoutArrow'); $('#sideNavBox .root.static > li.father > span').addClass('static menu-item ms-core-listMenu-item ms-displayInline ms-navedit-linkNode'); //do something special }, 1000);
How about you define function 2 and call it inside function 1 at it's end? 您如何定义函数2并在函数1的末尾调用它呢?
function fun1() {
$('#sideNavBox .root.static > li.static').each(function(){
if($(this).find('ul').length){
$(this).addClass('remove');}
$('#sideNavBox .root.static > li.remove > a').replaceWith(function(){
return $('<span class="additional-background ms-navedit-flyoutArrow">'+$(this).html()+'</span>' );
});
});
//calling function 2 here
fun2();
};
Why not simply call the fun2 at the end of the fun1 ? 为什么不简单在fun1的末尾调用fun2呢?
function fun2() { $('#sideNavBox .root.static > li.father > span').removeClass('additional-background ms-navedit-flyoutArrow'); $('#sideNavBox .root.static > li.father > span').addClass('static menu-item ms-core-listMenu-item ms-displayInline ms-navedit-linkNode'); //do something special } function fun1() { $('#sideNavBox .root.static > li.static').each(function() { if ($(this).find('ul').length) { $(this).addClass('remove'); } $('#sideNavBox .root.static > li.remove > a').replaceWith(function() { return $('<span class="additional-background ms-navedit-flyoutArrow">' + $(this).html() + '</span>'); }); }); fun2();//Call the fun2 }
You Call fun2() inside fun1() 您在fun1()内部调用fun2()
like this 像这样
function fun2() {
$('#sideNavBox .root.static > li.father > span').removeClass('additional-background ms-navedit-flyoutArrow');
$('#sideNavBox .root.static > li.father > span').addClass('static menu-item ms-core-listMenu-item ms-displayInline ms-navedit-linkNode');
//do something special
}
function fun1() {
$('#sideNavBox .root.static > li.static').each(function(){
if($(this).find('ul').length){
$(this).addClass('remove');}
$('#sideNavBox .root.static > li.remove > a').replaceWith(function(){
return $('<span class="additional-background ms-navedit-flyoutArrow">'+$(this).html()+'</span>' );
});
});
fun2() ;//Call function 2
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.