【问题标题】:jquery datatables.net check boxes not setting checked propertyjquery datatables.net 复选框未设置选中属性
【发布时间】:2012-09-18 06:56:37
【问题描述】:

所以我正在使用 JQuery datatables.net(www.datatables.net) 并取得了很大的成功。但最近我尝试添加一些复选框列,但没有取得多大成功。视觉上一切正常,但是当我实际选中/取消选中它时,它不会改变下面的底层值,无论是当我用 chrome 检查元素还是在 javascript 中捕获它时。 我是否需要更新表格或其他东西来刷新 DOM 对象?

Javascript 创建数据表:

$('#userGroupSettings').dataTable({
"bJQueryUI": true,
"aoColumns": [
/* ID */
    {
    "bVisible": false
},
/* Group Name */null,
/* Display Group */null,
/* Group Minimised*/null,
/* Send Fault Email*/null],
"aaSorting": [[1, "asc"]]

});

asp mvc razor 代码创建表:

<table id="userGroupSettings">
    <thead>
        <th>Group ID</th>
        <th>Group Name</th>
        <th>Display Group</th>
        <th title="When loading the webpage this will determine if the group is minimised or not">Group Minimised</th>
        <th title="Send me a fault email when an issue occurs in this group">Send Fault Email</th>
    </thead>
    <tbody>
    @foreach (MvcApplication2.Models.UserGroup group in user.Groups)
    {
        <tr>
            <td>@group.GroupID</td>
            <td>@group.GroupName</td>
            <td><input class="SettingsDisplayGroup" type="checkbox" name="displayGroup" value="@group.DisplayGroup" @(group.DisplayGroup ? "checked=\"checked\"" : "")/></td>
            <td><input class="SettingsMinimiseGroup" type="checkbox" name="minimiseGroup" value="@group.GroupMinimised" @(group.GroupMinimised ? "checked=\"checked\"" : "")/></td>
            <td><input class="SettingsSendFaultEmail" type="checkbox" name="sendFaultEmail" value="@group.SendFaultEmail" @(group.SendFaultEmail ? "checked=\"checked\"" : "")/></td>
        </tr>
    }
    </tbody>
</table>
<button id="saveUserGroupSettings">Save</button>

任何帮助表示赞赏

【问题讨论】:

  • 我很确定调试工具不会更新 html。我有和你一样的复选框,它们工作正常。我正在使用 FF 和 firebug,html 也没有更新,但它按预期工作。当您发布它们时它们工作正常吗?

标签: jquery asp.net-mvc asp.net-mvc-3 datatables


【解决方案1】:

选中的复选框仅意味着它的值将作为邮件发送,不需要更改任何其他内容。当然,如果您有多个具有相同名称的复选框,如果选中其中一个复选框,则会发送其值

【讨论】:

    【解决方案2】:

    所以我解决了这个问题。 我遇到的主要问题是,当我访问数据时,我将字符串转换为 javascript 元素,并且因为它没有 checked="checked" 属性,所以它被设置为 false:

    $($('#userGroupSettings').dataTable().fnGetData(i)[2])
    

    因此,我不得不使用 javascript 表格行元素并以这种方式搜索它们,而不是使用 fnGetData 循环遍历数据表:

    $('#userGroupSettings tbody tr').each(function () {
        var isChecked = $(this).find('.SettingsDisplayGroup')[0].checked;
    }
    

    我想因为我是从数据表内容(一个字符串)创建一个新的 jquery 元素,所以这里没有设置选中的属性

    请注意,如果您有任何 datatables.net 隐藏列,那么您将无法访问它们。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-09
      • 2011-04-14
      • 1970-01-01
      • 1970-01-01
      • 2018-01-10
      • 2011-04-05
      • 1970-01-01
      相关资源
      最近更新 更多