Skip to main content

Bug Tracker

Side navigation

#14571 closed bug (duplicate)

Opened November 24, 2013 03:47AM UTC

Closed November 28, 2013 08:40AM UTC

bug about checkbox in 1.10.2 and 2.0.2

Reported by: 312972510@qq.com Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.10.2
Keywords: Cc:
Blocked by: Blocking:
Description
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
    <script src ="jQuery/jquery-1.10.2.min.js"></script>
</head>
<body>
    <input id="allChk" type="checkbox" /><label for ="allChk">AllCheck</label><br />
    <input name="chk" id="Chk1" type="checkbox" /><label for ="Chk1">Check1</label><br />
    <input name="chk" id="Chk2" type="checkbox" /><label for ="Chk2">Check2</label><br />
    <input name="chk" id="Chk3" type="checkbox" /><label for ="Chk3">Check3</label><br />
    <input name="chk" id="Chk4" type="checkbox" /><label for ="Chk4">Check4</label>
</body>
</html>
<script type="text/javascript">
    $("#allChk").click(function () {
        $("input[name='chk']").attr('checked', this.checked);
        alert($('#Chk4').attr('checked'));
    });
</script>


When i click the 'AllCheck' third time,check4's attribute shows "checked",but it's not checked in the page,it also occured in 2.0.2,

but 1.8.3 works well.

Attachments (0)
Change History (2)

Changed November 24, 2013 08:40PM UTC by axl.jq comment:1

You are not using the jQuery functions as they should be used.

To check something using the attr functions, do `$elem.attr("checked", "checked"), not $elem.attr("checked", true)`.

To uncheck something using the attr functions, do `$elem.removeAttr("checked"), not $elem.attr("checked", false)`.

If your jQuery version supports prop, then please use `$elem.prop("checked", true) to check and $elem.prop("checked", false)` to uncheck.

To check if something is checked, use `$elem.is(":checked")`. Never read the attribute, becasue an element with attribute checked empty IS checked, but attr returns empty string and seems unchecked.

Changed November 28, 2013 08:40AM UTC by m_gol comment:2

resolution: → duplicate
status: newclosed

Duplicate of #13245.