jQuery:我可以在addClass()之类的之间调用delay()吗? [英] jQuery: Can I call delay() between addClass() and such?

查看:118
本文介绍了jQuery:我可以在addClass()之类的之间调用delay()吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单的事情:

$("#div").addClass("error").delay(1000).removeClass("error");

似乎不起作用.什么是最简单的选择?

doesn't seem to work. What would be the easiest alternative?

推荐答案

您可以创建一个新的队列项来删除该类:

You can create a new queue item to do your removing of the class:

$("#div").addClass("error").delay(1000).queue(function(next){
    $(this).removeClass("error");
    next();
});

或使用出队方法:

$("#div").addClass("error").delay(1000).queue(function(){
    $(this).removeClass("error").dequeue();
});

您需要调用nextdequeue的原因是让jQuery知道您已完成此排队项目,并且该项目应继续进行下一个项目.

The reason you need to call next or dequeue is to let jQuery know that you are done with this queued item and that it should move on to the next one.

这篇关于jQuery:我可以在addClass()之类的之间调用delay()吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆