简体   繁体   English

提交表单后如何在Laravel创建短时间提醒消息?

[英]How to create short time alert message in Laravel after submitting a form?

This is custom alert component to include on every page.这是要包含在每个页面上的自定义警报组件。 I tried it using session-flash, but it remains on page before and also after showing message.我尝试使用 session-flash,但它在显示消息之前和之后仍保留在页面上。 How to trigger and show it only after submitting form for short time.如何在短时间提交表单后才触发并显示。 using Laravel使用 Laravel

@section('alert-section')
   <div >
        <div class="alert alert-{{$color}}" role="alert" style="height: 36x; line-height:36px; padding:4px 20px;">
        <h5>{{$message}}</h5>
        </div>
    </div>
@endsection

session flash remains until next page reload, Is there any way to remove it after some seconds. session flash 一直保留到下一页重新加载,有没有办法在几秒钟后将其删除。

@if(isset($message))
    <x-alert color="success" message="Data has been updated successfully!" />
@endif

This code triggers the message after submitting form, but how to remove it after some seconds此代码在提交表单后触发消息,但如何在几秒钟后将其删除

You can refer to this sample code for setTimeout for hiding an element. setTimeout 隐藏元素可以参考这个示例代码。

setTimeout(() => {
  const box = document.getElementById('box');

  // 👇️ removes element from DOM
  box.style.display = 'none';

  // 👇️ hides element (still takes up space on the page)
  // box.style.visibility = 'hidden';
}, 1000); // 👈️ time in milliseconds

Or you can try this way with jQuery:或者你可以用 jQuery 试试这个方法:

setTimeout(function() {
    $('.alert').fadeOut('fast');
}, 1000); // 👈️ time in milliseconds

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM