当前位置:
首页 >
jquery-1.10.2 获取checkbox的checked属性总是undefined
发布时间:2025/3/20
57
豆豆
生活随笔
收集整理的这篇文章主要介绍了
jquery-1.10.2 获取checkbox的checked属性总是undefined
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
项目中用的jquery-1.10.2 需要检测一个checkbox的选中状态,想当然的用 .attr("checked") ,结果发现,无论是否选中,这个值都是 undefined 未定义。
查找资料,特此记录:
jq官网说明:
As of jQuery 1.6, the .attr() method returns undefined for attributes that have not been set. In addition, .attr() should not be used on plain objects, arrays, the window, or the document. To retrieve and change DOM properties, use the .prop()method.
.attr() 不能用于普通对象,数组,窗口,文档等,要重新获取改变dom属性,用.prop()方法。
用.prop方法确实可行。
贴一段代码如下:
[html] view plaincopy
总结
以上是生活随笔为你收集整理的jquery-1.10.2 获取checkbox的checked属性总是undefined的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 笔试题目“检测IPv4地址”的实现
- 下一篇: uploadify初体验