Javascript检查经典asp中的所有复选框

时间:2013-08-15 07:50:47

标签: javascript asp-classic

这是我第一次在Stackoverflow中提问

我在asp

中选择特定的框有同样的问题

我将旧帖称为

Javascript check all checkboxes in a table / asp.net

function toggleCheckBoxes(elem) {
  var div = document.getElementById('<% = divid.ClientID %>');
  var chk = div.getElementsByTagName('input');
  var len = chk.length;

  for (var i = 0; i < len; i++) {
    if (chk[i].type === 'checkbox') {
        chk[i].checked = elem.checked;
    }
  }
}

然后

'CheckAll
<input type="checkbox" id="chkAll" runat="server" onclick="toggleCheckBoxes(this)" />

但我的盒子是:

response.Write "</td>"
response.Write "<td nowrap><input type=checkbox name=process_1 "
if mEditRecMode and ConvertNullToString(mConsigneeArray(9))="1" then 
  response.Write " checked"
response.Write "/>1</td>"
response.Write "<td nowrap><input type=checkbox name=process_2 "
if mEditRecMode and ConvertNullToString(mConsigneeArray(10))="1" then 
  response.Write " checked"
response.Write "/>2</td>"
response.Write "<td nowrap><input type=checkbox name=process_3 "
if mEditRecMode and ConvertNullToString(mConsigneeArray(11))="1" then 
  response.Write " checked"
response.Write "/>3</td>"
response.Write "<td nowrap><input type=checkbox name=process_4 "
if mEditRecMode and ConvertNullToString(mConsigneeArray(12))="1" then 
  response.Write " checked"
response.Write "/>4</td>"
response.Write "<td nowrap><input type=checkbox name=process_5 "
if mEditRecMode and ConvertNullToString(mConsigneeArray(13))="1" then 
  response.Write " checked"
response.Write "/>5</td>"
response.Write "<td nowrap><input type=checkbox  name=process_6 "
if mEditRecMode and ConvertNullToString(mConsigneeArray(14))="1" then 
  response.Write " checked"
response.Write "/>6</td>"
response.Write "<td nowrap><input type=checkbox  name=process_7 "
if mEditRecMode and ConvertNullToString(mConsigneeArray(15))="1" then 
  response.Write " checked"
response.Write "/>7</td>"
response.Write "<td nowrap><input type=checkbox name=process_8 "
if mEditRecMode and ConvertNullToString(mConsigneeArray(16))="1" then 
  response.Write " checked"
response.Write "/>8</td>"
response.Write "<td nowrap><input type=checkbox name=process_9 "
if mEditRecMode and ConvertNullToString(mConsigneeArray(17))="1" then 
  response.Write " checked"
response.Write "/>9</td>"
response.Write "</tr>"
response.Write "</table>"

我如何选择它们/取消选择它们

请帮忙。

3 个答案:

答案 0 :(得分:0)

如果您使用jquery,可以试试这个:

function CheckAll(IsChecked) {
            $("input:checkbox").each(function () {
                $(this).prop('checked', IsChecked));
            });
        }

甚至更好,如果你根据这样的另一个复选框切换它们

 function CheckAll() {
            $("input:checkbox").each(function () {
                $(this).prop('checked', $('#ChkAll').is(':checked'));
            });
        }

答案 1 :(得分:0)

您有两个使用javascript或代码的选项:

1)遵循以下代码的Javascript:

     function toggleCheckBoxes(rb){
        var rbs = $('#rbData :radio');
        for (var i = 0; i < rbs.length; i++) {
            if (rbs[i] != rb) 
                rbs[i].checked = false;
        }
    }

2)通过将输入类型更改为asp:复选框并使其成为autopostback = true和onSelectedIndexChangd()函数,将复选框设置为

答案 2 :(得分:0)

选择/取消选中所有复选框与asp.net无关,我想。 向表中添加id属性,并添加与“checkall”标签关联的复选框,并定义其onclick事件处理程序。

这是demo,您可以检查并尝试更新自己的代码。

<强>更新 即使我没有关于asp.net的经验,但也有一些建议: 尽可能尝试使用循环语句,尝试使用支持ASP语法检查和突出显示的IDE,尝试学习一些常用的调试方法。

我认为它会对你有所帮助。