在JQuery中,是否可以在设置新的css规则后获得回调函数?

编程入门 行业动态 更新时间:2024-10-24 11:24:56
本文介绍了在JQuery中,是否可以在设置新的css规则后获得回调函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有 $('。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规则后获得回调函数?

本文发布于:2023-11-25 04:09:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628264.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:回调   函数   规则   JQuery   css

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!