【问题标题】:bootbox confirm popup box doesn't appear and the page freezesbootbox 确认弹出框没有出现并且页面冻结
【发布时间】:2019-09-20 09:23:59
【问题描述】:

常规的 js 确认弹出框有效,但是当我切换到引导框格式时,页面冻结。我已经通过包管理器控制台安装了最新版本的 bootbox 和 bootstrap。我查看了教程并遵循了一些确切的步骤,但碰巧遇到了同样的问题。我不确定我是否已经很好地解释了这个问题,因为我是新手。

这是我的代码。

@model List<Vidly.Models.Customer>

@{
    ViewBag.Title = "Customer";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Customer</h2>

<table id="customers" class="table table-striped">
    <thead>
        <tr>
            <th scope="col">Customers</th>
            <th scope="col">MembershipType</th>
            <th scope="col">Delete</th>

        </tr>
    </thead>
    <tbody>
        @foreach (var customer in Model)
        {

            <tr>
                <td>@Html.ActionLink(customer.Name, "Edit", "Customer", new { id = customer.Id }, null)</td>
                <td>@customer.MembershipType.MembershipTypes</td>
                <td><button data-customers-id="@customer.Id" class="btn-link js-delete">Delete</button></td>
            </tr>

        }
    </tbody>
</table>




@section scripts {



    <script>

       $(document).ready(function () {
            $("#customers .js-delete").on("click",".js-delete", function (e) {

              var button = $(this);
                bootbox.confirm("Are you sure you want to delete this customer?", function (result) {

                    if (result) {
                        $.ajax({
                            url: "/api/customers/" + button.attr("data-customer-id"),
                            method: "DELETE",
                            success: function () {
                                button.parents("tr").remove();
                            }
                        });
                    }
                });
            });
        });



    </script>


}

【问题讨论】:

    标签: jquery asp.net-core bootstrap-4 bootbox


    【解决方案1】:

    我刚刚遇到了同样的问题。我刚刚将引导程序版本更新到版本 4:

    update-Package bootstrap -Version 4.3.1

    之后它就起作用了。

    【讨论】:

      【解决方案2】:

      对于您当前的代码,您将无法找到按钮元素,请尝试更改选择器,例如

      $("#customers").on("click",".js-delete", function (e) {
          var button = $(this);
          bootbox.confirm("Are you sure you want to delete this customer?", function (result) {
          });
      });
      

      或者,

      $("#customers .js-delete").on("click",function (e) {
          var button = $(this);
          bootbox.confirm("Are you sure you want to delete this customer?", function (result) {
          });
      });
      

      要使用bootbox,你需要使用bootstrap.css而不是bootstrap-lumen.css

      试试

      bundles.Add(new StyleBundle("~/Content/css").Include(
                  "~/Content/bootstrap.css",
                  "~/Content/Site.css",
                  "~/Content/datatables/css/datatables.bootstrap.css"));
      

      【讨论】:

      • 感谢您的回复!我已经尝试了这两个实例,结果保持不变。页面冻结。
      • @AhmedBashir 冻结是什么意思? Web 浏览器控制台中是否有任何错误?是否有任何演示可以重现您的问题?
      • 我检查了控制台并没有出现任何内容,直到我不小心按了 Enter。状态码是 400,这是错误的请求。我注意到 'button.attr("data-customer-id")' 的参数拼写错误。然而,修复这个问题仍然没有解决引导箱确认没有出现。另外,当我说冻结时,我的意思是页面没有响应。单击时,所有按钮均不起作用。
      • 即使我做一些像这样简单的事情 '$(document).ready(function () { $("#customers .js-delete").on("click", function (e ) { var button = $(this); bootbox.alert("Hello world!"); }); }); '什么都没有出现
      • 不确定我错过了什么。这是我的项目github.com/Ahmed-Bashir/Vidly.git
      猜你喜欢
      • 1970-01-01
      • 2016-12-18
      • 1970-01-01
      • 1970-01-01
      • 2012-09-15
      • 2014-08-28
      • 2014-02-09
      • 2021-11-11
      • 1970-01-01
      相关资源
      最近更新 更多