jQuery的:检查所有复选框 [英] jQuery: check all checkboxes

查看:211
本文介绍了jQuery的:检查所有复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑这种情况:


  • < ASP:&的CheckBoxList GT; 母版页

  • 目标是在这个列表中的所有复选框在页面加载时进行检查。

  • 有在页面上许多复选框名单。

的标记:

    <asp:CheckBoxList runat="server" ID="chkSubscriptionType" 
        DataSourceID="myDS"
        CssClass="boxes" DataTextField="Name" DataValueField="Name"  />

渲染为:

&LT;输入ID =ctl00_cphContent_chkSubscriptionType_0类型=复选框NAME =$ ctl00 $ cphContent $ chkSubscriptionType 0/&GT;

问:你怎么可以使用jQuery检查所有箱子在这个 ASP:的CheckBoxList 的document.ready ?我看样无处不在,但在母版页使用命名约定抛出了样品中的其他地方。

Question: how can you use jQuery to check all boxes in this asp:CheckBoxList on document.ready? I see samples everywhere, but naming convention used by the master page throws off the samples in other places.

推荐答案

,该ID的将是自动生成的,搞砸了,你提到。您可以使用属性过滤器来选择包含您知道该部分的所有元素,那就是chkSubscriptionType。例如:

Because of the naming container, the ID's will be auto-generated and messed up, as you mention. You can use an attribute filter to select all elements that contain the part that you do know, that is, "chkSubscriptionType". For example:

$("input[id*=chkSubscriptionType]").attr("checked", "checked");

中的* =表示包含

这篇关于jQuery的:检查所有复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆