使用 jquery 在 X 秒后隐藏/删除标签
我想知道如何在一段时间后隐藏/删除标签。是否有一些内置的东西或者我是否使用线程(如果javascript可以做到这一点?)
I am wondering how can I hide/remove a tag after a certain amount of time. Is there some built in thing or do I do use threading(if javascript can do this?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您甚至不需要 jQuery 来实现“5 秒”部分:JavaScript 的内置
setTimeout
函数即可实现这一目的。结合 jQuery 进行 DOM 操作,您将得到:这里
5000
代表 5000 毫秒或 5 秒。您可以传递setTimeout
现有函数或(如本例中)匿名函数。You don't even need jQuery for the "5 seconds" part: JavaScript's built-in
setTimeout
function will do the trick. Incorporating jQuery for the DOM manipulation, you get:Here the
5000
represents 5000 milliseconds, or 5 seconds. You can passsetTimeout
an existing function or (as in this case) an anonymous function.尝试使用 .delay() 函数
http://api.jquery.com/delay/
Try to use .delay() function
http://api.jquery.com/delay/
这几乎与上面的答案类似,但在这个示例中,您只需按原样复制并将其粘贴到编辑器中即可工作。
This is almost similar to the above answers but in this example you just have to copy as it is and paste it in your editor then it will work.