在JQuery中,是否可以在设置新的css规则后获得回调函数? [英] In JQuery, Is it possible to get callback function after setting new css rule?
问题描述
我有 $('。element')。css(color,yellow)
和我需要下一个事件是在这一个,像 $('。element')。css(color,yellow,function(){alert(1);})
因为:
I have $('.element').css("color","yellow")
and I need that next event was only after this one, something looks like $('.element').css("color","yellow",function(){ alert(1); })
I need this because:
$('.element').css("color","yellow");
alert(1);
事件几乎是一次发生,这一刻调用动画效果中的错误)
events are happen at one time almost, and this moment call the bug in animation effect (alert(1) is just here for example, in real module it's animation)
推荐答案
回调只是异步函数必需的。 css函数将在代码执行继续之前完成,因此不需要回调。在代码中:
Callbacks are only necessary for asynchronous functions. The css function will always complete before code execution continues, so a callback is not required. In the code:
$('.element').css('color', 'yellow');
alert(1);
颜色将在警报触发之前更改。您可以通过运行以下命令来确认此操作:
The color will be changed before the alert is fired. You can confirm this by running:
$('.element').css('color', 'yellow');
alert($('.element').css('color'));
换句话说,如果你想使用回调,只需在css函数后执行: / p>
In other words, if you wanted to use a callback, just execute it after the css function:
$('.element').css('color', 'yellow');
cb();
这篇关于在JQuery中,是否可以在设置新的css规则后获得回调函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!