Using delay with HTML or text setting doesn't work

后端 未结 2 1739
忘了有多久
忘了有多久 2020-12-03 14:42

I have strange problem with the delay function here using the HTML function with it.

I set an HTML text by using $( \'#element\').html( \'Hello World\');

2条回答
  •  旧巷少年郎
    2020-12-03 15:10

    delay() defaults to the animation queue, for effects like fadeOut(), etc. You should use setTimeout() instead:

    window.setTimeout(function () {
        $("#element").html(' ');
    }, 3000);
    

    From http://api.jquery.com/delay/:

    jQuery.delay() is best for delaying between queued jQuery effects and such, and is not a replacement for JavaScript's native setTimeout function, which may be more appropriate for certain use cases.

提交回复
热议问题