gpt4 book ai didi

javascript - jQuery 1.6.4 和 RadioButtonList 问题

转载 作者:行者123 更新时间:2023-11-30 09:02:54 25 4
gpt4 key购买 nike

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

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

重现步骤:

1:电台A已经被选中。

2:选择单选B

3:在文本框中输入内容并跳出。

您将看到:A is checked 和 B is checked 警报。

那么从 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>

最佳答案

引用 OP:

So what exactly changed from 1.6.4 to 1.4.4 that is causing it to break?

单选按钮 checked 不是一个属性,它是一个属性。 jQuery 在 1.6 版中进行了更新以更正此语义错误。

改变这个...

.attr("checked")

对于这个...

.prop("checked")

编辑:

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

1) 它会增加代码的膨胀。

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

See this page to read the release notes on every version of jQuery .

也改变这个...

.removeAttr('checked')

对于这个...

.removeProp('checked')

关于javascript - jQuery 1.6.4 和 RadioButtonList 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7745387/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com