jQuery 1.6.4 and RadioButtonList issue

jQuery 1.6.4 and RadioButtonList issue

本文关键字:RadioButtonList issue and jQuery      更新时间:2023-09-26

从jQuery 1.4.4迁移到jQuery 1.6.4开始破坏我与radiobuttonlist相关的代码。

下面是复制奇怪行为的示例代码和步骤:

复制步骤:

1: Radio A已被选中。

2:选择电台B

3:在文本框中输入内容,然后tab out

您将看到:A被选中,B被选中。

那么从1.6.4到1.4.4到底是什么变化导致它崩溃的呢?

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
        <script src="http://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:

那么从1.6.4到1.4.4到底是什么变化导致它休息?

单选按钮checked不是属性,它是属性。jQuery在1.6版中更新以纠正这个语义错误。

改变这一切…

.attr("checked")
这个…

.prop("checked")

编辑:

关于OP关于为什么jQuery不向后兼容的评论:

1)这会增加代码的臃肿。

2) "向后兼容"实际上等于根本不解决这个问题。

请参阅本页阅读每个版本的jQuery发行说明。

.removeAttr('checked')
这个…

.removeProp('checked')