Jquery1.6版本后attr的变化
原文鏈接:http://www.cnblogs.com/-run/archive/2011/11/16/2251569.html
Jquery1.6版本后attr的變化
Jquery1.6版本后 attr 改動后的效果:
jquery1.6+版本:
?
下文來自www.jquery.com The difference betweenattributes and properties can be important in specific situations.Before jQuery 1.6, the .attr() method sometimes took property values into account when retrieving some attributes, which could cause inconsistent behavior.As of jQuery 1.6, the .prop() method provides a way to explicitly retrieve property values, while.attr() retrieves attributes For example, selectedIndex,tagName, nodeName, nodeType, ownerDocument,defaultChecked, and defaultSelected should be retrieved and set with the.prop() method. Prior to jQuery 1.6, these properties were retrievable with the.attr() method, but this was not within the scope of attr. These do not have corresponding attributes and are only properties.
| true (Boolean) Will change with checkbox state |
| true (Boolean) Will change with checkbox state |
| "checked" (String) Initial state of the checkbox; does not change |
| "checked" (String) Initial state of the checkbox; does not change |
| "checked" (String) Will change with checkbox state |
| true (Boolean) Changed with checkbox state |
?
?
?
//勾選后輸出: //attr('checked'): checked //.prop('checked'): true //.is(':checked'): true//取消勾選輸出://.attr('checked'): undefined //.prop('checked'): false //.is(':checked'): false
jquery1.4 版本:
?
勾選后輸出: //attr('checked'): true //.prop('checked') 1.6后版本才有這個方法 //.is(':checked'): true 取消勾選輸出://.attr('checked'): false //.prop('checked')1.6后版本才有這個方法 //.is(':checked'): false
?
結(jié)論: attr('checked'): 在1.6后版本,所獲取的值是 "checked"/"underfined"? ,之前所獲得的值是"false"/"true"。截然不同
?
長知識了
作者:那瞬間出處:http://www.cnblogs.com/-run/
本文版權(quán)歸作者和博客園共有,歡迎轉(zhuǎn)載,但未經(jīng)作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責(zé)任的權(quán)利。
總結(jié)
以上是生活随笔為你收集整理的Jquery1.6版本后attr的变化的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: spring mvc 返回html 乱码
- 下一篇: pcb天线和纯铜天线_各种PCB板载天线