jquery-1.10.2 获取checkbox的checked属性总是undefined
?項(xiàng)目中用的jquery-1.10.2 需要檢測(cè)一個(gè)checkbox的選中狀態(tài),想當(dāng)然的用 .attr("checked") ,結(jié)果發(fā)現(xiàn),無(wú)論是否選中,這個(gè)值都是 undefined 未定義。
?????? 查找資料,特此記錄:
?????? jq官網(wǎng)說(shuō)明:
??????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() 不能用于普通對(duì)象,數(shù)組,窗口,文檔等,要重新獲取改變dom屬性,用.prop()方法。
??????? 用.prop方法確實(shí)可行。
??????? 貼一段代碼如下:
???????
[html]?view plaincopy總結(jié)
以上是生活随笔為你收集整理的jquery-1.10.2 获取checkbox的checked属性总是undefined的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 笔试题目“检测IPv4地址”的实现
- 下一篇: ASP.NET中JSON的序列化和反序列