jQuery .delay不延迟 [英] jQuery .delay does not delay

查看:106
本文介绍了jQuery .delay不延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置元素的html,等待2秒钟,然后将html设置为其他内容?

How can I set the html of an element, wait 2 seconds, then set the html to something else?

示例:$("div").html("clicked").delay(2000).html("2 seconds have passed");

发生了什么:div脱离"2秒已过",而不是说单击" 2秒,然后显示"2秒已过".

What happens: the div gets "2 seconds have passed" off the bat, instead of saying "clicked" for 2 seconds, then displaying "2 seconds have passed".

我需要做类似.delay(2000, function() { $("div").html("2 seconds have passed"); })的事情吗?

Do I need to do something like, .delay(2000, function() { $("div").html("2 seconds have passed"); })?

此处的示例: http://jsbin.com/UfaYusU/1/edit

谢谢!

推荐答案

$.delay用于延迟队列中的动画,而不是暂停执行.

$.delay is used to delay animations in a queue, not halt execution.

尝试一下:

setTimeout(function() {
      // Do something after 2 seconds
}, 2000);

这篇关于jQuery .delay不延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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