jQuery 1.6中可能存在的错误 - $(...)。attr(" checked")无效 [英] Possible bug in jQuery 1.6 - $(...).attr("checked") is not working
本文介绍了jQuery 1.6中可能存在的错误 - $(...)。attr(" checked")无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的表单上有两个单选按钮,直到我开始使用jQuery 1.6,以下代码工作正常:
I have two radio buttons on my form and up until I started using jQuery 1.6 the following code worked fine:
<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,它总是显示none checked,因为 jQuery(radiobutton).attr(checked)
始终为空。
Once I start using jQuery 1.6, it always shows "none checked" because jQuery(radiobutton).attr("checked")
is always empty.
看看这个 jsfiddle ,并在1.5.2和1.6之间更改jQuery版本以查看我的意思。
Take a look at this jsfiddle, and change jQuery version between 1.5.2 and 1.6 to see what I mean.
推荐答案
看看这个问题: .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
问题
Also in the newest jQuery 1.6.1 they fixed some of the 1.6 attr
problems
这篇关于jQuery 1.6中可能存在的错误 - $(...)。attr(" checked")无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文