Javascript 点击功能只工作一次

Javascript 点击功能只工作一次,javascript,jquery,html,asp.net,Javascript,Jquery,Html,Asp.net,我有两个简单的js函数: CTCC.Transactions.PieceRecuClick = function (source) { $(".chk input[type='checkbox']").attr('checked', true); } CTCC.Transactions.PieceNonRecuClick = function (source) { $(".chk input[type='checkbox']").attr('checked', false);

我有两个简单的js函数:

CTCC.Transactions.PieceRecuClick = function (source) {
    $(".chk input[type='checkbox']").attr('checked', true);
}

CTCC.Transactions.PieceNonRecuClick = function (source) {
    $(".chk input[type='checkbox']").attr('checked', false);
}
这些影响相同的复选框,许多复选框看起来都像:

<asp:CheckBox runat="server" Class="chk" ID="chkPieceJust" Text="Recues" Enabled="true" Checked="<%# CheckBoxChecked(Container.DataItem as Transaction) %>" />
当我点击put to true时,它第一次工作,但只有第一次。。。我可以把很多时间推到错误的位置,而且它总是有效的。这不是什么大问题,一点也不,但我对这种奇怪的行为感到好奇。在这里,我按下true按钮后的html内容请注意,按下它后的内容始终相同,但它仅在第一次更改复选框

<input id="notUseful" type="checkbox" name="NotUseful" checked="checked">
这是我如何调用函数的:

   <input id="chkAllPieceJust" type="button" value="Mettre toutes les pièces justificatives à «Recues» " onclick="CTCC.Transactions.PieceRecuClick(this);" />
   &nbsp;&nbsp;
   <input id="chkAllPieceJust2" type="button" value="Mettre toutes les pièces justificatives à «Non-Recues» " onclick="CTCC.Transactions.PieceNonRecuClick(this);" />

@tymeJV在评论中回答了我的问题,我现在使用.prop函数而不是.attr,它工作得很好。

将attr设置为“checked”而不是true?正如你在html中所展示的那样?哈哈,我试过了,这是完全相同的行为,只是第一次起作用,我想知道绑定是否会影响复选框行为…不,我甚至删除了绑定,它不会改变任何东西这没有任何意义,如果html内容说它被选中,它应该被选中!!!!作为一个问题,如何/在哪里调用这些函数?你有没有检查控制台,有没有重新加载?它是明显未选中的还是当您从服务器端请求值时?