为什么这会立即清空文本(忽略延迟)?
$('#error_box_text').html('error text').delay(5000).html('')
#
这是关于 jQuery 1.4 的内容。
$('#error_box_text').html('error text').delay(5000).html('')
这是关于 jQuery 1.4 的内容。
delay
永远不会延迟常规方法,它只会延迟加入动画/效果链中的方法。如果您想延迟调用html()
,请使用queue
(http://api.jquery.com/queue/):
$('#error_box_text').html('error text').delay(5000).queue(function() {
$(this).html('')
});
如果你能做到那将会很好
$('#error_box_text').html('error text').delay(5000, function() { $(this).html('') });
但目前这还不可能。
尝试
var sel = $('#error_box_text');
sel.html('error text');
setTimeout(function(){
sel.html('');
}, 5000);
请参见delay()
jQuery.delay()最适合在排队的jQuery效果之间进行延迟,而不是替代JavaScript的本机setTimeout函数。
只需要使用类似这样的代码:
let r = $("#ur-div-id")
r.html(d)
setTimeout(() =>r.empty(), 4850);