简体   繁体   English

jQuery使用cssclass选择asp元素

[英]jquery select asp element with cssclass

I am attempting to check the checkbox (when clicking the label) by using its cssClass identifier. 我正在尝试使用其cssClass标识符选中复选框(单击标签时)。 It works fine if I use the checkbox ID but for some reason I am unable to access the checkbox using the class identifier. 如果我使用复选框ID,它会很好地工作,但是由于某种原因,我无法使用类标识符访问该复选框。

here is the javascript: 这是JavaScript:

   $(function () {
        $('#label').click(function () {
            $('.checkBox').prop('checked', true);
        });
   });

here is the html: 这是HTML:

<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="label" runat="server" ClientIDMode="Static" Text="Label"></asp:Label>
        <asp:CheckBox ID="CheckBox1" cssClass="checkBox" ClientIDMode="Static"  runat="server" />
    </div>
    </form>
</body>

If you look at rendered HTML for that page, you will see that checkbox is renderd as: 如果查看该页面的呈现HTML,您将看到该复选框呈现为:

<span class="checkBox" ClientIDMode="Static"><input id="CheckBox1" type="checkbox" name="CheckBox1" /></span>

The class is assigned to outer span. 该类被分配给外部范围。 You need to adjust your selector accordingly. 您需要相应地调整选择器。

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

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