简体   繁体   English

jQuery 和复选框,我看不到更改

[英]jQuery and checkboxes, i can't see the changes

I have many checkboxes in a ASP item repeater :我在 ASP 项目转发器中有很多复选框:

<asp:Repeater ID="rpPostes" runat="server" DataSource="<%# this.ItemsPostesBudgetaires %>">

Somewhere within the repeater, a checkBox described as :在中继器内的某个地方,一个复选框描述为:

<asp:CheckBox runat="server" Class="chk" ID="chkPieceJust" Text="Recues" Visible="<%#  Mode.HasFlag(ModeType._BoutonsApprobation)  %>" Enabled="<%# CheckBoxDispo() %>" Checked="<%# CheckBoxChecked(Container.DataItem as Transaction) %>" />

At the end of all that, a button that is suppose to turn every checkBoxes to true :最后,一个按钮可以将每个复选框变为 true :

<input id="chkAllPieceJust" type="button" value="Toutes Pièces Justificatives Recues" onclick="CTCC.Transactions.PieceRecuClick(this);" />

And finally here's my jQuery function :最后这是我的 jQuery 函数:

CTCC.Transactions.PieceRecuClick = function (source) {

$('.chk').attr('checked', true);

}

What happens after I click the button is that kind of html output :单击按钮后会发生那种 html 输出:

<span class="chk" checked="checked"><input ... blablabla

but nothing happens, checkboxes are not checked at all...但没有任何反应,根本没有选中复选框......

I can't figure what else do I need...我不知道我还需要什么......

The Checkbox control's CssClass property actually applies the class to a span element that wraps the checkbox itself. Checkbox控件的CssClass属性实际上将该类应用于包装复选框本身的span元素。 You can either apply the class directly to the checkbox element by assigning it in the codebehind like this:您可以通过在代码隐藏中分配类直接将类应用于复选框元素,如下所示:

MyCheckBox.InputAttributes["class"] = "chk";

Or modify your jquery to look for the input child element of the .chk element, like this或者修改你的jquery来查找.chk元素的输入子元素,像这样

$(".chk input[type='checkbox']").prop('checked', true);

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

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