Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何在几秒钟后隐藏flash消息?_Jquery_Flash Message - Fatal编程技术网

Jquery 如何在几秒钟后隐藏flash消息?

Jquery 如何在几秒钟后隐藏flash消息?,jquery,flash-message,Jquery,Flash Message,在我的应用程序中,用户可以为其他用户发布挑战。因此,在成功发布挑战后,我将为同一个问题显示一条flash消息。但现在我想在几秒钟后隐藏此消息。所以我写了以下代码: $(document).ready(function(){ setTimeout(function() { $("#successMessage").hide('blind', {}, 500) }, 5000); }); <div id="successMessage" style="text

在我的应用程序中,用户可以为其他用户发布挑战。因此,在成功发布挑战后,我将为同一个问题显示一条flash消息。但现在我想在几秒钟后隐藏此消息。所以我写了以下代码:

$(document).ready(function(){
    setTimeout(function() {
        $("#successMessage").hide('blind', {}, 500)
    }, 5000);
});

<div id="successMessage" style="text-align:center; width:100%">
    <FONT color="green">
        <%if flash[:alert]=="Your challenge is posted successfully."%> 
            <h4><%= flash[:alert] if flash[:alert].present? %>
        <%end%>
    </font>
</div>
$(文档).ready(函数(){
setTimeout(函数(){
$(“#成功消息”).hide('blind',{},500)
}, 5000);
});
但是此代码没有隐藏div“successMessage”。

您可以尝试:

setTimeout(function() {
    $('#successMessage').fadeOut('fast');
}, 30000); // <-- time in milliseconds
setTimeout(函数(){
$('successMessage').fadeOut('fast');
}, 30000); //  您可以使用来实现这一点

$(document).ready(function(){
    $("#successMessage").delay(5000).slideUp(300);
});

有时,仅仅将“显示框”设置为“无”是不够的,最好完全删除它。详情如下:

setTimeout(function() {
    $('.alert-box').remove();
}, 30000); 

有人用此解决方案向stackoverflow发布了一个类似的问题:

<script type="text/javascript">window.setTimeout("document.getElementById('successMessage').style.display='none';", 2000); </script>

<div id="successMessage"> bla bla bla
</div>
window.setTimeout(“document.getElementById('successMessage').style.display='none';”,2000);
呜呜呜呜

我想分享链接,但我再也找不到了。谢谢你的帮助,神秘人

您需要在发布消息后调用
setTimeout
,而不是在
document.ready()
@sweety我想您需要的是标签而不是标签,我编辑了它。