模态背景所涵盖的Bootstrap模型

时间:2015-12-26 01:08:18

标签: javascript jquery css twitter-bootstrap-3 modal-dialog

我有简单的html页面来显示bootstrap模式,但是当我启动模型时 - 它被模态背景覆盖, 我检查了myModal-1040的z-index和模态背景的z-index是1030 检查了stackoverflow中的所有帖子,但没有一个解决了我的问题 请帮忙

<html>
<head>
    <link href="" rel="stylesheet">
    <link href="Content/bootstrap.min.css" rel="stylesheet">
    <script src="Scripts/jquery-1.10.2.min.js"></script>
    <script src="Scripts/bootstrap.min.js"></script>
</head>
<body>




    <a href="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal</a>

    <div id="myModal" class="modal hide fade in" aria-hidden="true">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">X</button>
            <h3 id="myModalLabel">Log in</h3>
        </div>
        <div class="modal-body">
            <form class="modal-form" id="loginform">
                <input type="text" name="username" placeholder="login" id="username">
                <input type="text" name="password" placeholder="password" id="userpassword">
            </form>
        </div>
        <div class="modal-footer">
            <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
            <button class="btn btn-success">Login</button>
        </div>
    </div>

</body>
</html>​

2 个答案:

答案 0 :(得分:2)

你忘记了一些事情:

  • <div class="modal-dialog">
  • <div class="modal-content">

你还添加了一些不必要的东西:

  • hide
  • 上的<div id="myModal" class="modal fade in" aria-hidden="true">课程
  • in
  • 上的<div id="myModal" class="modal fade in" aria-hidden="true">课程

您的工作代码如下所示:

<a href="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal</a>

<div id="myModal" class="modal fade in" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">X</button>
        <h3 id="myModalLabel">Log in</h3>
      </div>
      <div class="modal-body">
        <form class="modal-form" id="loginform">
          <input type="text" name="username" placeholder="login" id="username">
          <input type="text" name="password" placeholder="password" id="userpassword">
        </form>
      </div>
      <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
        <button class="btn btn-success">Login</button>
      </div>
    </div>
  </div>
</div>

这是一个JsFiddle,可以在工作环境中展示它。

要阅读有关模态的所有内容,请查看this

希望这有帮助!

答案 1 :(得分:0)

从模式中删除hide类。

JSFdiddle

<a href="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal</a>

<div id="myModal" class="modal fade in" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">X</button>
    <h3 id="myModalLabel">Log in</h3>
  </div>
  <div class="modal-body">
    <form class="modal-form" id="loginform">
      <input type="text" name="username" placeholder="login" id="username">
      <input type="text" name="password" placeholder="password" id="userpassword">
    </form>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <button class="btn btn-success">Login</button>
  </div>
</div>