ASP.NET-设置复选框的CssClass [英] ASP.NET - Setting CssClass of a CheckBox

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

问题描述

以下代码

((CheckBox)e.Row.FindControl("exportCb")).CssClass = "enabledExport";

创建html

<span class="enabledExport"><input id="_ctl0_ContentPlaceHolder1_gridviewName__ctl2_exportCb" type="checkbox" name="_ctl0:ContentPlaceHolder1:gridviewName:_ctl2:exportCb" /></span>

对于asp.net gridview列

For the asp.net gridview column

<asp:TemplateField HeaderText="Export">
                        <ItemTemplate>
                            <asp:CheckBox runat="server" ID="exportCb"/>        
                        </ItemTemplate>
                        <ItemStyle/>
                    </asp:TemplateField>

我需要使用jQuery

I need to use jquery

$('.enabledExport').toggle()

选中/取消选中(作为切换)复选框.因为CssClass标记在<span>上,所以代码将尝试切换<span>而不是<input>.我怎样才能解决这个问题?

to check/uncheck (as a toggle) the checkboxes. Because the CssClass is marked on the <span> the code is going to try to toggle a <span> instead of the <input>. How can I fix this?

我不介意解决方案是在jquery还是asp.net上,只要它可以工作即可.如果代码只是将输入标记为应有的样子,我就会喜欢它.

I don't mind if the solution is on jquery or asp.net side as long as it works. I'd love it if the code just marked the input like its supposed to...

推荐答案

如果您尝试显示/隐藏复选框,则可以执行以下操作:

If you're trying to show/hide the checkbox you could do this:

$('.enabledExport input:checkbox').toggle()

但是我认为您想做的是:

but what I think you're trying to do is:

var $checkbox = $('.enabledExport input:checkbox');
$checkbox.attr("checked", !$checkbox.is(":checked"));

这篇关于ASP.NET-设置复选框的CssClass的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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