jquery-1.10.2 获取checkbox的checked属性总是undefined
生活随笔
收集整理的這篇文章主要介紹了
jquery-1.10.2 获取checkbox的checked属性总是undefined
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
?項目中用的jquery-1.10.2 需要檢測一個checkbox的選中狀態(tài),想當然的用 .attr("checked") ,結(jié)果發(fā)現(xiàn),無論是否選中,這個值都是 undefined 未定義。
?????? 查找資料,特此記錄:
?????? jq官網(wǎng)說明:
??????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() 不能用于普通對象,數(shù)組,窗口,文檔等,要重新獲取改變dom屬性,用.prop()方法。
??????? 用.prop方法確實可行。
??????? 貼一段代碼如下:
???????
[html]?view plaincopy總結(jié)
以上是生活随笔為你收集整理的jquery-1.10.2 获取checkbox的checked属性总是undefined的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 笔试题目“检测IPv4地址”的实现
- 下一篇: uploadify初体验