Bug Tracker

Opened 6 years ago

Closed 6 years ago

#13895 closed bug (duplicate)

Error in chage input:checkbox

Reported by: juanpa_842@… Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:

Description

Current version 1.9.1

<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
        <script type="text/javascript">

           function set_checked(value)
           {
             $('input[name=foo]').attr('checked', value);
           }
            function show_checked()
           {
             alert($('input[name=foo]').is(':checked'));
           } 
        </script>
    </head>
    <body>
        <form>
            <input type="checkbox" name="foo" value="bar"> 
            <input type="button" onclick="show_checked()" value="Show"> 
            <input type="button" onclick="set_checked(true)" value="On"> 
            <input type="button" onclick="set_checked(false)" value="Off">
        </form>
    </body>
</html>

Change History (3)

comment:2 Changed 6 years ago by jorgebg

Hi, This is not a bug. You should use prop method instead of attr.As of jQuery 1.6, the .prop() method provides a way to explicitly retrieve property values, while .attr() retrieves attributes. Kind regards, Jorgebg

comment:3 Changed 6 years ago by timmywil

Resolution: duplicate
Status: newclosed

Duplicate of #13245.

Note: See TracTickets for help on using tickets.