Bootstrap 3 个模态背景落在模态前面

Bootstrap 3 modal backdrop falls in front of modal

我试图搜索答案,也尝试了很多答案,但无法通过。 我的模态弹出窗口有问题 up.I 想在我的模态弹出窗口 up.After 上显示 10 秒倒数计时器 十秒结束后,模态弹出窗口必须消失。 现在,尝试这样做我面临两个问题。

  1. 我试过的定时器不工作。
  2. 模态弹出窗口显示不正确。

模式弹出窗口的问题在这里:

<!DOCTYPE html>
<html lang="en">
  <head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- The above 3 meta tags *must* come first in the head; any other head   content must come *after* these tags -->
  <meta name="description" content="">
   <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">

    <link rel="stylesheet" type="text/css" href="css/prettyPhoto.css">
    <link rel="stylesheet" type="text/css" href="css/ff.master.css">
    <link rel="stylesheet" type="text/css" href="css/main.css">
    <link rel="stylesheet" type="text/css" href="css/owl.carousel.css">
    <link rel="stylesheet" type="text/css" href="css/owl.transitions.css">
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="css/bootstrap-theme.css">
    <link rel="stylesheet" type="text/css" href="css/bootstrap-theme.min.css">



<!-- Custom styles for this template -->

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
     <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js">       </script>
       <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script>var cid = '1679091c5a880faf6fb5e6087eb1b2dc';</script>
   </head>

  <body onLoad="$('#myModal').modal('show');">

<div class="site-wrapper">


     <div class="site-wrapper-inner">

    <div class="cover-container">

      <div class="masthead clearfix" align="center">
        <div class="inner">
          <h3><img src="img/logo.png" class="img-rounded" width="250"     height="100"</h3>
        </div>
      </div>

      <div class="inner cover" align="center">

        <h5 class="m-b fs-14">It's easy to get started. Call reception or ask waiter<br> for internet coupon. Enter the credentials recieved below and you will be online in no time.</h5>


        $(if chap-id)
          <form name="sendin" action="$(link-login-only)" method="post">
            <input type="hidden" name="username" />
            <input type="hidden" name="password" />
            <input type="hidden" name="dst" value= />
            <input type="hidden" name="popup" value="true" />
          </form>

          <script type="text/javascript" src="js/md5.js"></script>
          <script type="text/javascript">
          <!--
              function doLogin() {
            document.sendin.username.value = document.login.username.value;
            document.sendin.password.value = hexMD5('$(chap-id)' +    document.login.password.value + '$(chap-challenge)');
            document.sendin.submit();
            return false;
              }
          //-->
          </script>
        $(endif)



<h3>Enter the credentials below</h3>
        <div class="b p img-rounded">
        <form name="login" class="form-inline"action="$(link-login-only)" method="post"
          $(if chap-id) onSubmit="return doLogin()" $(endif)>
          <input type="hidden" name="dst" value="" />
          <input type="hidden" name="popup" value="true" />
          <div class="form-group">
            <input type="text" class="form-control input-lg col-md-4" placeholder="Username" name="username" value="$(username)">
          </div>
          <div class="form-group">
            <input type="text" class="form-control input-lg col-md-4" placeholder="Password" name="password">
          </div>
          <button type="submit" class="btn btn-success btn-lg">Login</button>
        </form>

        $(if error)<div class="text-center text-danger text-error m-t">$(error)</div>$(endif)

        </div>

      </div>

      <br>
      <div class="mastfoot" align="center">
        <div class="inner">

        </div>
      </div>

    </div>

  </div>

</div>

        <!-- Bootstrap core JavaScript
        ================================================== -->
        <!-- Placed at the end of the document so the pages load faster -->
         <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>

        <script src="js/owl.carousel.min.js"></script>
        <script src="js/mousescroll.js"></script>
        <script src="js/smoothscroll.js"></script>
        <script src="js/jquery.prettyPhoto.js"></script>
        <script src="js/jquery.isotope.min.js"></script>
        <script src="js/jquery.inview.min.js"></script>
        <script src="js/wow.min.js"></script>
        <script src="js/main.js"></script>   


       <script src="js/jquery-1.11.2.min.js"></script>
        <script src="js/bootstrap.min.js"></script>
        <script src="js/jquery.validate.min.js"></script>
        <script src="js/jquery.form.min.js"></script>
        <script src="js/jquery-validate.bootstrap-tooltip.js"></script>
        <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
        <script src="js/ie10-viewport-bug-workaround.js"></script>



    <script>
        $(document).ready(function() {
          $('#sms-form').load('http://fireflywifi.co.in/register/index/'+cid);

          $('body').on('click', '#smsBtn', function() {
            $('#sms-form form').validate({
              submitHandler: function(form) {
                $('#smsBtn').html('<i class="glyphicon glyphicon-share-alt"></i> Sending...');
                $('#smsBtn').attr('disbaled', 'disabled');
                $(form).ajaxSubmit({
                  target: '#sms-form'
                });
                return false;
              },
              tooltip_options: {
                '_all_': { placement: 'bottom' }
              },
              highlight: function(element) {
                  $(element).closest('.form-group').addClass('has-error');
              },
              unhighlight: function(element) {
                  $(element).closest('.form-group').removeClass('has-error');
              }
            });
          });
        });
        </script>



     <script type="text/javascript">


        var Timer;
        var TotalSeconds;


        function CreateTimer(TimerID, Time) 
        {
            Timer = document.getElementById('TimerID').innerHTML;
            TotalSeconds = Time;

            UpdateTimer()
            window.setTimeout("Tick()", 1000);
        }

        function Tick()
        {
            if (TotalSeconds <= 0) 

            return;
            TotalSeconds -= 1;
            UpdateTimer()
            window.setTimeout("Tick()", 1000);
        }

        function UpdateTimer() 
        {
            var Seconds = TotalSeconds;

            var Days = Math.floor(Seconds / 86400);
            Seconds -= Days * 86400;

            var Hours = Math.floor(Seconds / 3600);
            Seconds -= Hours * (3600);

            var Minutes = Math.floor(Seconds / 60);
            Seconds -= Minutes * (60);


            var TimeStr = ((Days > 0) ? Days + " days " : "") + LeadingZero(Hours) + ":" + LeadingZero(Minutes) + ":" + LeadingZero(Seconds)


            document.getElementById("TimerID").innerHTML = TimeStr;
        }


        function LeadingZero(Time)
            {

            return (Time < 10) ? "0" + Time : + Time;
            }

       </script>

        <div class="modal" id="myModal" tabindex="-1" role="dialog" aria-  labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
        <div class="modal-content">
        <script type="text/javascript">window.onload =CreateTimer("timer", 30)</script>
        <h4>You will be connected in <button style="text-align:center" id="timer" style="text-align:center"> </button> seconds </h4>
        </div>
         <div class="modal-body">
         <form id="form" class="form" name="form" action="sendemail.php" method="post">

         <div class="content">
         <div class="intro"></div>
         <div id="section0">

         </div>

         </div>
         </form>
         </div>
         <div class="modal-footer">

         <button type="button" class="btn btn-default" data-  dismiss="modal">Close</button>
              </div>
            </div>
          </div>
         </div>

          </body>
          </html>



 [1]: https://dl.dropboxusercontent.com/u/94517486/screenshot.png

你有三个问题

  1. 您的模态窗口缺少起始 <div class="modal-header"> 标签,这就是模态窗口混乱的原因(几乎总是由缺少或额外的标签引起)
  2. 你的 javascript 调用 Timer = document.getElementById('TimerID').innerHTML;document.getElementById("TimerID").innerHTML = TimeStr; 但你的 html 有 id="timer",改变一个或另一个使它们匹配
  3. 您的模式上的关闭按钮有 data- dismiss="modal">Close</button> 请注意 data- dismiss 中的 space。去掉那个 space 否则按钮不会关闭模式。

关于你的计时器,因为你真正想要的是从给定的秒数开始倒计时,你现在已经完成了。一个简单的递归函数就足够了:

function startCountdown(seconds) {
    $('#timer').html(seconds); // set the text to the current value of seconds
    if(seconds>0) setTimeout(function(){ startCountdown(seconds - 1); }, 1000); // if we havent hit 0 yet, wait 1 second and call the function again after subtracting 1 from "seconds"
    else{
        $('#myModal').modal('hide');
    }
}
startCountdown(10); // call the function with some number of seconds to countdown from 

Here's a working jsFiddle