[英]How can I make this div element dissapear
I have this code on my website and this div appears when u successfully post a comment. 我的网站上有此代码,当您成功发表评论时,就会显示此div。 Now I want the div element disappear after 3-5 seconds. 现在,我希望div元素在3-5秒后消失。 Here's my code: 这是我的代码:
echo "<div class='granted'><p>Comment posted.</p></div>";
echo "<script type=\"text/javascript\">
setTimeout(function() {
$('.granted').fadeOut('fast');
}, 3000);
</script>";
Thanks! 谢谢!
Your code works perfectly. 您的代码运行完美。 I think you have missed to link the script library. 我认为您错过了链接脚本库的链接。 Adding this line before the PHP script does the trick. 在PHP脚本之前添加此行即可达到目的。
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
$(document).ready(function(){
setTimeout(function(){
$('.granted').hide();}, 5000);
});
It's not good practice to include HTML tags inside php codes. 在php代码中包含HTML标记不是一个好习惯。
<div class='granted'><p>Comment posted.</p></div>
<script>
$(function(){
setInterval(function(){
$('.granted').fadeOut(1);
},5000);
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.