简体   繁体   English

选择所有复选框已选中所有复选框均未选中标签中的图像

[英]select all checkbox checked all checkboxes have image in the label are not checked

I have check boxes and had a label on that and have check box image. 我有复选框,上面有一个标签,并且有复选框图像。 when i click the check box inner check box is checked and i toggle the image in the label when checked and unchecked.but when i click on select all check box browser check boxes are checked internally but my images in the label are not changed like checked. 当我单击复选框时,选中内部复选框,并在选中和未选中时切换标签中的图像。但是,当我单击“选中所有复选框”时,浏览器内部复选框已选中,但标签中的图像未更改(如选中) 。 I had tried this on 我试过了

if(chkSelectAll)
{
    var allSelected = true;             
    for (var i = 0; i < document.forms[0].elements.length; i++)
    {
        var e = document.forms[0].elements[i];
        if (e.type == 'checkbox')
        {
            var strName="";
            strName = e.name;
            if(strName.indexOf(datalist) >= 0 && !e.checked)
            {
                allSelected = false;
                break;
            }                           
        }
    }
    if(allSelected)
        currentBox.checked = true;
    else
        currentBox.checked = false;
}

My HTML code is 我的HTML代码是

Select All 全选

' Text='<%#GUISupport.GUIUtils.ViewEncode(DataBinder.Eval(Container.DataItem, "Label").ToString()) %>' onclick="CheckSelectAll(this,chkSelectAllPrimaryCustomFields,'lstPrimaryCustomFields');" 'Text ='<%#GUISupport.GUIUtils.ViewEncode(DataBinder.Eval(Container.DataItem,“ Label”)。ToString())%>'onclick =“ CheckSelectAll(this,chkSelectAllPrimaryCustomFields,'lstPrimaryCustomFields');” runat="server" ID="chkPrimaryCustomFields" /> runat =“ server” ID =“ chkPrimaryCustomFields” />

could any one help me out thanks in advance. 有人可以帮助我吗,谢谢。

I want the common code that loads whenpage get loaded 我想要页面加载时加载的通用代码

Why don't you change the labels when if condition is true? 如果条件为真,为什么不更改标签?

in for loop change labels accordingly 在for循环中相应地更改标签

for (var i = 0; i < document.forms[0].elements.length; i++) {

//change labels

}

You are not changing the labels at all in your code, please post your HTML that this script points to, so that we can give you a more detailed solution as to how to achieve this. 您根本不需要更改代码中的标签,请发布此脚本指向的HTML,以便我们为您提供实现此目的的更详细的解决方案。

(this answer will be edited based on responses). (此答案将根据回复进行编辑)。

you can following this code. 您可以遵循此代码。 In html code 在html代码中

<table>
            <thead>
                <tr>
                    <th
                        @using (Html.BeginForm("admin","Admin",FormMethod.Get))
                        {
                            <input type="checkbox" name="ckbCheckAll" id="ckbCheckAll" value="" onclick="checkAll();" />
                        }
                    </th>
                    <th>No</th>
                    <th>Title</th>
                </tr>
            </thead>

            @foreach(var item in Model)
            {
                i++;
                <tr>
                    <td>
                        <input type="checkbox" name="cid" id="@i" value="@item.ID" />
                    </td>
                    <td>@i</td>
                    <td>@item.Title</td>
                </tr>
            }
</table>

And function checkAll() in javascript: 并在javascript中使用checkAll()函数:

function checkAll() {
        var check = document.getElementById("ckbCheckAll").checked;
        for (var i = 1; i <= document.getElementsByName("cid").length; i++) {
            document.getElementById(i).checked = check;
        }
    }

Above code is working. 上面的代码正在工作。 Hope to help for you 希望对您有所帮助

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

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