简体   繁体   English

点击功能只能使用一次

[英]Click function only works one time

I have these two simple js functions : 我有这两个简单的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);
}

These affect the same checkboxes, a lot of CheckBoxes that all look like : 这些会影响相同的复选框,很多CheckBox看上去都像这样:

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

When i click on ("put to true") it works the first time, but only the first time... I can push lots of time on ("put to false") and it always work. 当我单击(“设置为真”)时,它第一次起作用,但是只有第一次...我可以花很多时间(“设置为假”),并且它总是起作用。 It's not a big issue, not at all, but i'm being curious about that strange behaviour. 这不是一个大问题,根本不是问题,但是我很好奇这种奇怪的行为。 here, my html content after i push the "true" button (note that it's always the same after i push it, but it changes the checkboxes only the first time) 在这里,我按下“ true”按钮后的html内容(请注意,按下按钮后它始终是相同的,但是它仅在第一次更改复选框)

<input id="notUseful" type="checkbox" name="NotUseful" checked="checked">

This is how i call the functions: 这就是我所谓的函​​数:

   <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 funtion而不是.attr,它运行完美。

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

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