jQuery 睡眠功能?

发布于 2024-09-17 01:12:29 字数 562 浏览 3 评论 0原文

可能的重复:
Jquery:如何睡眠或延迟?

var main = $('#main_content');
main.append("<img id=\"throbber\" src='/pre_config/css/images/throbber.gif' alt='Loading. Please wait.' />");
sleep(3000);
$("#main_content").load("/pre_config/function.php?type="+type+"piz&count=1", successCallback );

我想在这里睡3秒

sleep is not defined
[Break on this error] sleep(3000);
func2

Possible Duplicate:
Jquery: how to sleep or delay?

var main = $('#main_content');
main.append("<img id=\"throbber\" src='/pre_config/css/images/throbber.gif' alt='Loading. Please wait.' />");
sleep(3000);
$("#main_content").load("/pre_config/function.php?type="+type+"piz&count=1", successCallback );

I want to sleep for 3 seconds here

sleep is not defined
[Break on this error] sleep(3000);
func2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

離殇 2024-09-24 01:12:29

使用 JavaScript setTimeout()

setTimeout(function() {
    $("#main_content").load("/pre_config/function.php?type="+type+"piz&count=1", successCallback );
}, 3000);

编辑:

要使用.delay(),您需要将延迟代码添加到动画队列中。

$("#main_content")
.delay(3000)
.queue(function( n ) {
    $(this).load("/pre_config/function.php?type="+type+"piz&count=1", successCallback )
           .dequeue();
});

Use a javascript setTimeout().

setTimeout(function() {
    $("#main_content").load("/pre_config/function.php?type="+type+"piz&count=1", successCallback );
}, 3000);

EDIT:

To use .delay(), you would need to add the delayed code to an animation queue.

$("#main_content")
.delay(3000)
.queue(function( n ) {
    $(this).load("/pre_config/function.php?type="+type+"piz&count=1", successCallback )
           .dequeue();
});
肥爪爪 2024-09-24 01:12:29

请记住,JavaScript 不仅是单线程的,而且与页面渲染共享同一线程。因此,JavaScript 中没有内置的阻塞函数,因为这会导致页面 UI 无响应。

您应该考虑使用计时器,使用 setTimeout()setInterval() 或 jQuery 的 delay()。查看 @patrick 的回答了解几个示例。

Keep in mind that JavaScript is not only single threaded, but it shares the same thread with the page rendering. Therefore there are no in-built blocking functions in JavaScript, because that would make the page UI unresponsive.

You should consider using timers instead, using setTimeout(), setInterval(), or jQuery's delay(). Check out @patrick's answer for a couple of examples.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文