gpt4 book ai didi

jquery - jQuery 1.6 中可能存在的错误 - $(...).attr ("checked") 不起作用

转载 作者:行者123 更新时间:2023-12-01 00:37:24 25 4
gpt4 key购买 nike

我的表单上有两个单选按钮,直到我开始使用 jQuery 1.6 为止,以下代码工作正常:

<input type="radio" id="radio1" name="test"/>
<input type="radio" id="radio2" name="test"/>
<input type="button" onclick="testcheck()" value="Test"/>
<script>
function testcheck()
{
if (jQuery("#radio1").attr("checked"))
alert("first button checked");
else if (jQuery("#radio2").attr("checked"))
alert("second button checked");
else
alert("none checked")
}
</script>

一旦我开始使用 jQuery 1.6,它总是显示“未检查”,因为 jQuery(radiobutton).attr("checked") 始终为空。

看看这个 jsfiddle ,并将 jQuery 版本更改为 1.5.2 和 1.6,看看我的意思。

最佳答案

看看这个问题:.prop() vs .attr()

请尝试在您的代码中使用此方法:

function testcheck()
{
if (jQuery("#radio1").prop("checked"))
alert("first button checked");
else if (jQuery("#radio2").prop("checked"))
alert("second button checked");
else
alert("none checked")
}

也在最新的 jQuery 1.6.1他们修复了一些 1.6 attr 问题

关于jquery - jQuery 1.6 中可能存在的错误 - $(...).attr ("checked") 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5969598/

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