模式内部的按钮不适用于Bootstrap 4,但适用于Bootstrap 3

时间:2018-07-20 00:02:48

标签: php jquery laravel twitter-bootstrap-3 bootstrap-4

我在laravel项目中工作,我可以使用一个按钮来显示模式,并且在该模式中有一个删除按钮,并且正在使用botstrap 3,但在使用bootrsap 4时不起作用。

这是我的html代码, 这些CDN正在运行:

   <!-- jQuery -->
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
 <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.1/js/bootstrap.min.js"></script>

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">

当我使用这些CDN时,模态中的删除按钮不再起作用:

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<!-- Popper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>

我的模态:

 <div id="deleteModal" class="modal fade" role="dialog">
        <div class="modal-dialog">
            <div class="modal-cliente">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">×</button>
                    <h4 class="modal-orden_de_compra"></h4>
                </div>
                <div class="modal-body">
                    <h3 class="text-center">¿Estas seguro de que quieres eliminar este pedido?</h3>
                    <br />
                    <form class="form-horizontal" role="form">
                        <div class="form-group">
                            <label class="control-label col-sm-2" for="id">id:</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="id_delete" disabled>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-sm-2" for="orden_de_compra">Orden de compra:</label>
                            <div class="col-sm-10">
                                <input type="name" class="form-control" id="orden_de_compra_delete" disabled>
                            </div>
                        </div>
                    </form>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-danger delete" data-dismiss="modal">
                            <span id="" class='glyphicon glyphicon-trash'></span> Delete
                        </button>this delete button doesnt work with Bootstrap 4 but is working with bootstrap 3
                        <button type="button" class="btn btn-warning" data-dismiss="modal">
                            <span class='glyphicon glyphicon-remove'></span> Close
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>

我的js:

    <script type="text/javascript">


   // delete a post
        $(document).on('click', '.delete-modal', function() { //this function works with bootstrap 4
            $('.modal-orden_de_compra').text('Delete');
            $('#id_delete').val($(this).data('id'));
            $('#orden_de_compra_delete').val($(this).data('orden_de_compra'));
            $('#deleteModal').modal('show');
            id = $('#id_delete').val();
            orden_de_compra = $('#orden_de_compra_delete').val();
            alert(id); 
        });
        $('.modal-footer').on('click', '.delete', function() { //this function doesnt work with bootstrap 4
            $.ajax({
                type: 'DELETE',
                url: 'posts/' + id,
                data: {
                    '_token': $('input[name=_token]').val(),
                },
                success: function(data) {
                    toastr.success('Pedido eliminado exitosamente!', 'Notificación', {timeOut: 5000});
                    $('.item' + data['pedido_id']).remove();
                    alert('.item' + data['pedido_id']);
                }
            });
        });

</script

1 个答案:

答案 0 :(得分:0)

好的...我将同时摘录两个片段,以让您了解其中的区别。

BS3:

$('.modal-footer').on('click', '.delete', function() { 
  console.log("I'm here.");
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.1/js/bootstrap.min.js"></script>

<button type="button" data-toggle="modal" data-target="#deleteModal">Open Modal</button>

<div id="deleteModal" class="modal fade" role="dialog">
  <div class="modal-dialog">
    <div class="modal-cliente">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">×</button>
        <h4 class="modal-orden_de_compra"></h4>
      </div>
      <div class="modal-body">
        <h3 class="text-center">¿Estas seguro de que quieres eliminar este pedido?</h3>
        <br />
        <form class="form-horizontal" role="form">
          <div class="form-group">
            <label class="control-label col-sm-2" for="id">id:</label>
            <div class="col-sm-10">
              <input type="text" class="form-control" id="id_delete" disabled>
            </div>
          </div>
          <div class="form-group">
            <label class="control-label col-sm-2" for="orden_de_compra">Orden de compra:</label>
            <div class="col-sm-10">
              <input type="name" class="form-control" id="orden_de_compra_delete" disabled>
            </div>
          </div>
        </form>
        <div class="modal-footer">
          <button type="button" class="btn btn-danger delete" data-dismiss="modal">
            <span id="" class='glyphicon glyphicon-trash'></span> Delete
          </button>this delete button doesnt work with Bootstrap 4 but is working with bootstrap 3
          <button type="button" class="btn btn-warning" data-dismiss="modal">
            <span class='glyphicon glyphicon-remove'></span> Close
          </button>
        </div>
      </div>
    </div>
  </div>
</div>

看过Migrating to v4 documention之后,对此一无所知...
我最终通过比较the v4 markup来找到%&*可能有什么不同。

这是非常微妙的...我不知道class="modal-cliente"的用途是什么……可能是某些不影响v3的错误。但是看来这是v4的问题。 role="document"可能也很重要...抱歉,我无法更详细地解释。 ;)

在下面的标记中查找2条稍作更改的行。

BS4:

$('.modal-footer').on('click', '.delete', function() { 
  console.log("I'm here.");
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>

<button type="button" data-toggle="modal" data-target="#deleteModal">Open Modal</button>

<div id="deleteModal" class="modal fade" role="dialog">
  <!-- Those 2 lines are slightly changed -->
  <div class="modal-dialog" role="document">
    <div class="modal-content">
    <!-- ============================ -->
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">×</button>
        <h4 class="modal-orden_de_compra"></h4>
      </div>
      <div class="modal-body">
        <h3 class="text-center">¿Estas seguro de que quieres eliminar este pedido?</h3>
        <br />
        <form class="form-horizontal" role="form">
          <div class="form-group">
            <label class="control-label col-sm-2" for="id">id:</label>
            <div class="col-sm-10">
              <input type="text" class="form-control" id="id_delete" disabled>
            </div>
          </div>
          <div class="form-group">
            <label class="control-label col-sm-2" for="orden_de_compra">Orden de compra:</label>
            <div class="col-sm-10">
              <input type="name" class="form-control" id="orden_de_compra_delete" disabled>
            </div>
          </div>
        </form>
        <div class="modal-footer">
          <button type="button" class="btn btn-danger delete" data-dismiss="modal">
            <span id="" class='glyphicon glyphicon-trash'></span> Delete
          </button>this delete button doesnt work with Bootstrap 4 but is working with bootstrap 3
          <button type="button" class="btn btn-warning" data-dismiss="modal">
            <span class='glyphicon glyphicon-remove'></span> Close
          </button>
        </div>
      </div>
    </div>
  </div>
</div>