点击后Jquery延迟 [英] Jquery Delay After Click

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

问题描述

我正在创建一个web应用程序...

我得到了一种游戏,我的想法是当用户完成每个关卡时出现一个对话框信息,这很好。



现在我的问题是我想在用户点击完成按钮5秒后显示此消息。



多数民众赞成我的代码:

  $('#option-main-menu')。click(function (){
target.append('\
< div id =confirm> \
< h1>您确定要存在吗?< / h1> \
< / div> \
');
});

我也试着用 append()。Delay(10000)但无效。



在此先感谢您。

使用 setTimeout(),延迟时间为5000毫秒。
$ b

$( )按钮()()()()(){} console.log(clicked ... waiting ...); setTimeout(function(){alert(Called after delay。);},5000) ;

 < script src =https:// ajax .googleapis.com / ajax / libs / jquery / 1.11.1 / jquery.min.js>< / script>< button type =button>点击我< /按钮>  

出于好奇,为什么要等5秒钟才提示用户回复一个行动?这是很长的时间;足够长的时间让他们点击了一堆其他东西(如果没有其他东西)。


I'm creating a web app...

i got a kind of game, my idea is when the user completes each level appears a dialog box with some information, it is fine.

Now my issue is i want to show this message 5 seconds after the user clicks on the finish button.

thats my code:

$('#option-main-menu').click(function(){
        target.append('\
            <div id="confirm">\
                <h1>Are You Sure Want to Exist?</h1>\
                <a href="#" id="dialog-confirm">Yes</a><a href="#" id="dialog-cancel">No</a>\
            </div>\
        ');
    });

also i tryed with append().Delay(10000) but does not work.

Thanks in advance.

解决方案

Use setTimeout() with a delay of 5000 ms.

$("button").click(
    function() {
        console.log("clicked...waiting...");

        setTimeout(
            function() {
                alert("Called after delay.");
            },
            5000);
    });

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button type="button">Click Me</button>

Just out of curiosity, why would you want to wait 5 seconds before prompting the user in response to an action? That's a long time; long enough for them to have clicked on a bunch of other things (if nothing else).

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

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