嗨,我已经尝试过使用一些脚本来显示Flash消息,但该脚本无法显示,但无法正常工作。显示Flash消息,直到我刷新页面为止。

控制器:

if ($this->email->send())
        {
           $this->session->set_flashdata('msg','<div class="alert alert-success text-center" id="successMessage">Thank you for contacting us we will get back to you soon!</div>');
            redirect('contact');
        }
        else
        {
            $this->session->set_flashdata('msg','<div class="alert alert-danger text-center">There is error in sending mail! Please try again later</div>');
            redirect('contact');
        }


视图:

<script>
$(function() {
// setTimeout() function will be fired after page is loaded
// it will wait for 5 sec. and then will fire
// $("#successMessage").hide() function
setTimeout(function() {
    $(".alert-success").hide('blind', {}, 500)
}, 5000);
});
</script>
<div class="container">

<div class="row contactpageback">

        <div class="col-lg-6 contactuspagedetails">
            <form name="contact"  id="contactform" enctype="multipart/form-data" method="post" action="<?php echo base_url();?>contact">
            <?php echo  $this->session->flashdata('msg');?>
            <?php if(isset($msg)){?>
             <?php echo $msg;?>
               <?php } ?>

最佳答案

这是你想要的吗。希望这可以帮助你。



$(function() {
// setTimeout() function will be fired after page is loaded
// it will wait for 5 sec. and then will fire
// $("#successMessage").hide() function

    $(".hide-it").hide(5000);

});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
<body>
<div>
  <h1 class='hide-it'>Flash Data value here</h1>
</div>
</body>
</html>

10-04 11:29