在我获取数据并将它们设置到标签中后,5秒后我想清除这个标签。我尝试:
$('#ajax_message').html(data).delay(5000).html("");
但这不起作用。我怎样才能做到这一点?
最佳答案
根据文档:
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.
长话短说,.delay()
适用于 queued functions 。您应该使用 setTimeout()
来代替。
$('#ajax_message').html(data)
setTimeout(function(){
$('#ajax_message').html("");
},5000);
关于javascript - 5 秒后删除内容表单标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27291402/