Javascript boostrap,整个页面在模态中出现重复

时间:2017-02-18 23:36:09

标签: javascript twitter-bootstrap modal-dialog

My problem on screenshot

触发模态时遇到问题。页面重复进入模态。当我点击带有代码的按钮时,问题就开始了:

<a href=<?php echo $route_destroy;?> data-toggle="modal" data-target="#confirm-submit" class="btn btn-danger btn-xs"><i class="fa fa-trash-o"></i> Desactivar </a>

我的html模式代码:

<div class="modal fade" id="confirm-submit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                Confirm Submit
            </div>
            <div class="modal-body">
                Are you sure you want to submit the following details?
                <table class="table">
                    <tr>
                        <th>Last Name</th>
                        <td id="lname"></td>
                    </tr>
                    <tr>
                        <th>First Name</th>
                        <td id="fname"></td>
                    </tr>
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                <a href="#" id="submit" class="btn btn-success success">Submit</a>
            </div>
        </div>
    </div>
</div>

我的jquery代码:

<script type="text/javascript">    
  $(document).ready(function () {
    $('#submit').click(function(){
         /* when the submit button in the modal is clicked, submit the form */
        alert('submitting');
        $('#formfield').submit();
    });
  });
  </script>

1 个答案:

答案 0 :(得分:1)

如果没有看到您的表单和任何JavaScript,很难确定。

我认为可能是因为您提交的是表单而不会阻止默认操作。不这样做可能会导致表单在提交时重定向到页面。

<script type="text/javascript">    
  $(document).ready(function () {
    $('#submit').click(function(){
        alert('submitting');
        $('#formfield').submit(function(event) {
           // Add some JavaScript to change your modal here
           event.preventDefault();
        });
    });
  });
</script>