简体   繁体   English

HTML5支持具有SelectAll的复选框

[英]Html5 support having SelectAll for checkboxes

i have the following Razor view inside my asp.net mvc web application:- 我在asp.net mvc Web应用程序中具有以下Razor视图:-

foreach (var item in Model) {
    <tr id="@item.RouterID">
        <td>

 <input type="checkbox" name="CheckBoxSelection" 
                               value="@item.RouterID.ToString()"
                                /> 
@Html.ActionLink("Edit", "Edit","Router", new { id=item.RouterID },null)

Which will display a checkboxes inside table rows. 这将在表格行内显示一个复选框。 so does Html-5 support having SelectAll checkbox , for selecting all the checkboxes that have the same name or id ? Html-5是否支持具有SelectAll复选框,以便选择所有具有相同名称或ID的复选框? Thanks 谢谢

Edit i add the following selectAll checkbox:- 编辑我添加以下全选复选框:-

<input type="checkbox" 
                               name="selectAll"
                id="selectAll" 

                                /> 

and i wrote the following script:- 我写了以下脚本:

$('body').on("change", "#selectAll", function () {
    var checkflag = "false";
    var checkboxes = document.getElementsByName('CheckBoxSelection');
    function check() {
        if (checkflag == "false") {
            for (i = 0; i < checkboxes.length; i++) {
                checkboxes[i].checked = true;
            }
            checkflag = "true";

        } else {
            for (i = 0; i < checkboxes.length; i++) {
                field[i].checked = false;
            }
            checkflag = "false";

        }
    }
});

but it did not work,, i mean the checkboxes will never get checked/unchekced .. can anyone adivce? 但是它没有用,我的意思是复选框永远不会被选中/取消选中..有人可以离开吗?

Add a checkbox for Select All / Deselect All 为“全选/取消全选”添加复选框

<input type="checkbox" id="selectAll" name="selectAll" />

Add a css class named "checkBoxClass" 添加一个名为“ checkBoxClass”的css类

foreach (var item in Model) {
    <tr id="@item.RouterID">
        <td>

 <input class='checkBoxClass' type="checkbox" name="CheckBoxSelection" 
                               value="@item.RouterID.ToString()"
                                /> 
@Html.ActionLink("Edit", "Edit","Router", new { id=item.RouterID },null)
}

In jquery 在jQuery中

 $(document).ready(function () {
    $("#selectAll").click(function () {
        $(".checkBoxClass").prop('checked', $(this).prop('checked'));
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM