简体   繁体   English

n秒后自动关闭引导警报

[英]Closing a Bootstrap Alert Automically after n seconds

I'm creating a new site using the Bootstrap Framework and have issues trying to automatically close a boot strap alert after n seconds. 我正在使用Bootstrap框架创建一个新站点,并且在尝试在n秒后自动关闭引导警报时遇到问题。

The main page contains a modal login form. 主页包含模式登录​​表单。 Once a user attempts to login, providing the entered details are incorrect, i display a alert on the main page containing an error (wrong password, Unknown username etc). 一旦用户尝试登录(提供的详细信息不正确),我就会在主页上显示一个包含错误(错误密码,未知用户名等)的警报。

So the alert appears fine, but i cant automatically close it, code below if anyone is able to help, thanks. 因此,警报似乎很好,但我无法自动将其关闭,如果有人可以帮助,请在下面的代码中进行感谢,谢谢。

PHP (returns error and displays alert) PHP(返回错误并显示警报)

<?php

// show potential errors / feedback (from login object)
if (isset($login)) {
    if ($login->errors) {
        foreach ($login->errors as $error) {
            $AlertError = $error;

            echo '<div class="alert alert-warning alert-dismissible" role="alert" id="loginerror">
               <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
               <strong>' . $AlertError . '</strong>
               </div>';
        }
    }
}

I've tried calling a java script functions from the above PHP code to then close the alert with no luck 我尝试从上面的PHP代码中调用Java脚本函数,然后关闭警报,但没有运气

$("#loginerror").fadeTo(2000, 500).slideUp(500, function(){
$("#loginerror").alert('close');

You have to have a delay like setTimeout() and just fire the .click() on the close button: 您必须像setTimeout()这样的延迟时间,然后在关闭按钮上触发.click()

if($('#loginerror').length){ // <-----checks if loginerror div is available
   setTimeout(function(){
      $('#loginerror').find('.close')[0].click();
   },1*1000);
}

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

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