jQuery 1.6.4 and RadioButtonList issue
Moving from jQuery 1.4.4 to jquery 1.6.4 started breaking my code related to radiobuttonlist.
Here is a sample code and steps to replicate weird behavior:
Steps to reproduce:
1: Radio A is already selected.
2: Select radio B
3: Enter something in textbox and tab out.
You will see: A is checked and B is checked alerts.
So what exactly changed from 1.6.4 to 1.4.4 that is causing it to break?
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="htt开发者_运维问答p://ajax.microsoft.com/ajax/jquery/jquery-1.6.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
function txtchanged(tb) {
$(".rbl").find("input[type='radio']").each(function () {
alert($(this).val() + " " + $(this).attr("checked"));
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:RadioButtonList ID="RadioButtonList1" runat="server" CssClass="rbl">
<asp:ListItem Text="A" Value="A" Selected="True" />
<asp:ListItem Text="B" Value="B" />
</asp:RadioButtonList>
<asp:TextBox ID="tb" runat="server" CssClass="tb" onblur="txtchanged(this)"></asp:TextBox>
</form>
</body>
</html>
Quote OP:
So what exactly changed from 1.6.4 to 1.4.4 that is causing it to break?
Radio button checked
is not an attribute, it's a property. jQuery was updated in version 1.6 to correct this semantic error.
Change this...
.attr("checked")
to this...
.prop("checked")
EDITS:
As to the OP's comment about why jQuery is not backward compatible:
1) It would add an accumulation of bloat to the code.
2) To be "backward compatible" would be virtually the same as not fixing this problem at all.
See this page to read the release notes on every version of jQuery.
Also change this...
.removeAttr('checked')
to this...
.removeProp('checked')
精彩评论