JQuery Mobile刷新复选框只能运行一次 - .checkboxradio('refresh')问题

时间:2013-07-12 10:25:48

标签: jquery jquery-mobile checkbox refresh

我遇到了一个奇怪的问题。我有一个带复选框列的表格。我正在使用JQuery Mobile复选框。我希望点击与该行关联的行,然后单击此行中的复选框。

JS:

$(document).on('pagecreate', function (event) {
    bindRowClick();
});

function bindRowClick() {
    $('.productTable').find('tr').click(function () {
        var chck = $(this).find('td.hyperLink').find('input[type=checkbox]:first');
        var chckStatus = chck.is(':checked');
        alert("chckStatus 1: " + chckStatus);
        alert("!chckStatus: " + !chckStatus);
        chck.attr('checked', !chckStatus).checkboxradio().checkboxradio('refresh');
        alert("chckStatus 2: " + chck.is(':checked'));
    });
}

HTML:这位于<td class="hyperlink">

<fieldset data-role="controlgroup" id="divCheckbox">
     <asp:CheckBox runat="server" ID="checkboxSelect" CssClass="custom chckSelect" 
          meta:resourcekey="checkboxSelectResource1" />
     <asp:Label ID="lblForChck" CssClass="lblForChck" AssociatedControlID="checkboxSelect" runat="server" 
          meta:resourcekey="lblForChckResource1" />
</fieldset>

当我点击第1行时发生的事情(直到现在才选中复选框):

first alert returns: "chckStatus 1: false"
second alert returns: "!chckStatus: true"
third alert returns: "chckStatus 2: true"

当我点击 SAME 第2行时(先前已选中复选框)时发生了什么:

first alert returns: "chckStatus 1: true"
second alert returns: "!chckStatus: false"
third alert returns: "chckStatus 2: false"

现在是奇怪的部分

当我再次点击同一行时 - 而不是选中复选框(就像第一次)我得到以下结果:

first alert returns: "chckStatus 1: true"
second alert returns: "!chckStatus: false"
third alert returns: "chckStatus 2: false"

我发现可能与此问题有关: Previously working ".checkboxradio('refresh')" now broken in a3

1 个答案:

答案 0 :(得分:15)

而不是使用.attr()使用.prop()然后使用.checkboxradio('refresh')

  

<强> Demo