Delaying click event

后端 未结 4 1123
滥情空心
滥情空心 2021-02-20 11:54

I\'m wondering whether there\'s a simple way to delay the click event from being processed for a specified period of time. For example we could have

$(\'#someEle         


        
4条回答
  •  失恋的感觉
    2021-02-20 12:35

    setTimeout allows you to delay running code by however many ms you want

    setTimeout(function(){
        console.log('Stuff be done'); //This will be delayed for one second
    }, 1000);
    

    In reality, if you're dealing with ajax you want to respond when the ajax call is complete. It may take more or less than 1000ms. $.ajax allows you do this with the .done() method. This is an example from the docs:

    $.ajax({
        url: "test.html",
        context: document.body
    }).done(function() {
        $(this).addClass("done");
    });
    

提交回复
热议问题