dtkz3186 2018-07-20 00:02
浏览 199
已采纳

模态中的按钮不能与Bootstrap 4一起使用,但正在使用Bootstrap 3

Im working in a laravel project and I can use a button in order to show a modal and I have a delete button inside this modal and is working using botstrap 3 but is not working using bootrsap 4. ¨

This is my html code, these CDN are working:

   <!-- 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">

and when I use these cdn my delete button inside my modal doesnt work anymore:

<!-- 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>

My modal:

 <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>

My 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条回答 默认 最新

  • douza1373 2018-07-20 02:08
    关注

    Okay... I will do both snippets for you to see the difference.

    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>

    After a look at the Migrating to v4 documention and finding an absolute nothing about this...
    I finally found it by comparing the v4 markup in search of what the %&* can be different.

    It's pretty subtile... I don't know what class="modal-cliente" was for... Potentially something wrong that wasn't affecting v3. But it seems it is the issue with v4. The role="document" may be important too... Sorry, I can't explain in more details. ;)

    Look for the 2 slightly changed lines in the markup below.

    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>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号