【问题标题】:Bootstrap - Uncaught TypeError: Cannot read property 'click' of undefined on checkbox clickBootstrap - 未捕获的类型错误:无法读取复选框单击时未定义的属性“单击”
【发布时间】:2021-09-11 13:40:28
【问题描述】:

我在我的 cshtml 页面中有一个简单的 mvc 表,我试图在其中一列中添加一个复选框,但是当我点击复选框时出现以下错误:

未捕获的类型错误:无法读取未定义的属性“点击”

现在这个错误来自 bootstrap.js 文件:

 b.prototype.click = function(b) {
        var c = a(b.currentTarget).closest("tr").find(this.options.target)[0];
        if (a(b.target)[0] !== c)
            if (b.preventDefault(),
            c.click)
                c.click();
            else if (document.createEvent) {
                var d = document.createEvent("MouseEvents");
                d.initMouseEvent("click", !0, !0, window, 0, 0, 0, 0, 0, !1, !1, !1, !1, 0, null),
                c.dispatchEvent(d)
            }
    }

我可以看到“c”的值是未定义的,因此,它会引发错误。如果我从布局页面评论 bootstrap.js 文件。一切正常。

这是我的桌子:

  <table id="DashboardTab" class="table table-striped rowlink table-hover" data-link="row">
        <tr>
            <th>
                Name
            </th>
            <th>
                Groups
            </th>
            <th>Active</th>
            <th></th>
        </tr>
        
        @{var i = 0;}
        @foreach (var item in Model)
        {
            <tr>
                <td style="display: none">@item.Id</td>
                <td>
                     @Html.ActionLink(item.Name, "Edit", new { id = item.ID })
                </td>
                <td>
                     <i>All</i>
                </td>
                <td>
                    @if (item.IsStd)
                    {
                        @Html.CheckBox("Active" + i, item.IsActive.Value)
                    }
                </td>
                <td style="display: none">@item.IsStandard</td>
                <td>
                    <i class="fa fa-arrows-v" aria-hidden="true"></i>
                </td>
            </tr>
            i++;
        }

    </table>

我做错了什么?

更新: 所以问题是因为“data-link="row"。实际上该行是可点击的,因此,点击复选框就像点击行一样。我怎样才能只点击几行而不是全部?

【问题讨论】:

    标签: css .net asp.net-mvc razor bootstrap-4


    【解决方案1】:

    所以问题出在表中的 data-link=row 上。我只需要几行即可点击,所以我从表中删除了data-link=row,并在添加的 onclick() 事件中:

    if(item.IsStd){
      <tr onclick="location.href = '@Url.Action( "Edit", "Home",new {id = item.ID})'">
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-08
      • 2021-11-02
      • 1970-01-01
      • 2014-01-03
      • 1970-01-01
      • 1970-01-01
      • 2021-12-22
      • 2016-02-26
      相关资源
      最近更新 更多