dt3999 2016-01-08 11:09
浏览 31
已采纳

n秒后自动关闭引导程序警报

I'm creating a new site using the Bootstrap Framework and have issues trying to automatically close a boot strap alert after n seconds.

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

// 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

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

1条回答 默认 最新

  • duangu6431 2016-01-08 11:13
    关注

    You have to have a delay like setTimeout() and just fire the .click() on the close button:

    if($('#loginerror').length){ // <-----checks if loginerror div is available
       setTimeout(function(){
          $('#loginerror').find('.close')[0].click();
       },1*1000);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题