dougu1896 2015-09-20 09:32
浏览 46
已采纳

登录失败时如何在php中调用bootstrap模式?

I want to show a modal when username is wrong, I have the php code, not full but there is the error :

         header("location:admin.php");
         exit(); 
    } else

  header("location:admin_login.php?error=1");

};
if (isset($_GET['error'])==1){echo "<script type=\"text/javascript\">$('#myModal').modal('show');</script>";
exit();}
?>

And the javascript doesn't work.

Modal code:

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

I have included but still not working, do you have any idea why?

  • 写回答

3条回答 默认 最新

  • duanhao5038 2015-09-20 13:54
    关注

    Make sure the script DOM ready and remove exit(); from PHP, even if the script will be DOM ready, exit(); will not let the modal show and even after these changes if the modal still not show, make sure check the jQuery library, you may be running modal show script somewhere in middle of page but jQuery library may be in footer so check your console log for error. Remember jQuery library always comes first.

    <?php if (isset($_GET['error'])==1){ ?>
        <script type="text/javascript">
        $(document).ready(function(){
            $("#myModal").modal("show");
        });
        </script>
    <?php } ?>
    

    See in Action

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里