简体   繁体   English

如何在asp.net中通过JavaScript动态选中/取消选中html复选框

[英]How to dynamically check/uncheck html checkbox by JavaScript in asp.net

在此输入图像描述 I know that several questions about this topic have been asked, but I was unable to find an answer for my case. 我知道有关于这个主题的几个问题已被提出,但我无法找到我的案例的答案。

I have gridview. 我有gridview。 In that Checkbox. 在那个复选框中。

Here, I want to do functionality like When I check on exp_id 1515001101 then others all exp_id 1515001101 get automatically check. 在这里,我想做的功能就像当我检查exp_id 1515001101然后其他所有exp_id 1515001101自动检查。 在此输入图像描述

     function checkUncheckHeaderCheckBoxforSubmit(obj)
 {var checkboxCell;var expidCell;

          var grid = document.getElementById("<%=grdViewLocalConvence.ClientID %>"); 
for (i = 1; i < grid.rows.length - 2; i++)

    { for (i = 1; i < grid.rows.length - 2; i++) 
{ checkboxCell = grid.rows[i].cells[8];
           expidCell = grid.rows[i].cells[0];

          var exp_id = expidCell.innerText;
        for (j = 0; j < checkboxCell.childNodes.length; j++) 
    {if (checkboxCell.childNodes[j].type == "checkbox") 
    {  if (checkboxCell.childNodes[j].checked == true)
     { var exp_id = expidCell.innerText;  
                          GridVwHeaderChckbox.rows[i].cells[8].getElementsByTagName("INPUT")[0].checked = 
    exp_id.checked;
          }}}}

Please help me. 请帮我。 Thanks. 谢谢。

try this 尝试这个

 $(".checkboxid").change(function() {// the first checking checkbox
        if(this.checked) {
            $('.checkboxid').attr('checked', true);// here put change checkbox details that are checked automatically
        }
    });

If you want to fix the state of these check boxes remains same then best idea is save data to db and retrieve each time the page load happends 如果你想修复这些复选框的状态保持不变那么最好的想法是将数据保存到db并在每次页面加载发生时检索

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

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