Jquery Delay After Click

前端 未结 7 1988
無奈伤痛
無奈伤痛 2020-12-29 08:58

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

相关标签:
7条回答
  • 2020-12-29 09:05

    try:

    $('#option-main-menu').click(function(){
        setTimeout(
            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>\
            ');
           }
            , 5000);
       });
    
    0 讨论(0)
  • 2020-12-29 09:10

    You could try using setTimeout().

    Example.

    setTimeout(function(){
        // do stuff here, in your case, append text
    }, 5000);
    

    The 5000 can be replaced with any value of time that determines the length of the delay in milliseconds.

    0 讨论(0)
  • 2020-12-29 09:15

    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).

    0 讨论(0)
  • 2020-12-29 09:23

    This will work

    $("button").click(
    function() {
        console.log("clicked...waiting...");
    
        setTimeout(
            function() {
                alert("Called after delay.");
            },
            5000);
    });
    
    0 讨论(0)
  • 2020-12-29 09:26
    $yourThing.click(function(){
        setTimeout(function(){do your thing here},5000)
    })
    
    0 讨论(0)
  • 2020-12-29 09:27

    $("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>

    0 讨论(0)
提交回复
热议问题