BootStrap 3 Modal逐渐淡出表格,为什么? (动画问题)

时间:2014-08-21 21:28:44

标签: javascript php jquery ajax twitter-bootstrap

我正在使用JQuery和BootStrap进行基本的ajax表单提交。我已经设法在模态中使用ajax $ .load()和$ .post()来计算表单。我关心的是当我关闭模态时,表格会在模态消失时出现。

的index.php     

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
       <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</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>

<!-- Button trigger modal -->
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
    Launch demo modal
</button>

<?php include('includes/footer.php'); ?>

page1.php中

<form action="page2.php" method="post" id="form">
    <input type="text" name="firstName" id="firstName" required/>
    <input type="submit" value="submit" class="submit"/>
</form>

使page2.php

<?php $name = $_POST['firstName']; 
echo $name . "<br>" . "Page 2!"; ?>

的JavaScript

$(document).ready(function(){

   $('.btn').click(function(){
      $('.modal-body').load('page1.php');
   });

   $('.submit').click(function(){
      var firstName = $('#firstName').val();
        if(firstName == ''){
            $.load('page1.php');
        }
        $.post('page2.php', {firstName: firstName}, function(html){
           $('.modal-body').html(html);
        });
      return false;
   });

});

0 个答案:

没有答案