繁体   English   中英

提交表单后显示Bootstrap模式

[英]Showing a Bootstrap modal after form is submitted

我想在成功提交表单后重新加载页面时显示“谢谢”模式。

这是我在<head>底部的PHP:

<?php
    if (isset($_POST["email"]) && !empty($_POST["email"]))
    {
        $response_text = "Thanks, we'll be in touch soon!";
        include('connect.php');
        mysqli_query($con, "INSERT INTO sh_betalist (email, ip_address, signup_loc) VALUES ('" . $_POST['email'] . "', '" . $_SERVER['REMOTE_ADDR'] . "', '" . "homepage')");
        ?>
        <script type="text/javascript"> $('#thankyouModal').modal('show'); </script>
        <?php
    }
?>

这一切都很好,除了显示模态,这不会发生。 我在JS控制台中没有出现任何错误。

这是我在<body>底部的模态:

<div class="modal fade" id="thankyouModal" tabindex="-1" role="dialog" aria-labelledby="thankyouLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">Thank you for pre-registering!</h4>
            </div>
            <div class="modal-body">
                <p>You'll be the first to know when Shopaholic launches.</p>                     
                <p>In the meantime, any <a href="http://shopaholic.uservoice.com/" target="_blank">feedback</a> would be much appreciated.</p>
            </div>    
        </div>
    </div>
</div>

尝试在javascript周围包装一个$(document).ready

<?php
    if (isset($_POST["email"]) && !empty($_POST["email"]))
    {
        $response_text = "Thanks, we'll be in touch soon!";
        include('connect.php');
        mysqli_query($con, "INSERT INTO sh_betalist 
        (email, ip_address, signup_loc) VALUES ('" . $_POST['email'] . "', '" . 
        $_SERVER['REMOTE_ADDR'] . "', '" . "homepage')");
 ?>
       <script type="text/javascript"> 
       $(document).ready(function(){
           $('#thankyouModal').modal('show');
       });
      </script>
    <?php
}
?>

暂无
暂无

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

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