日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Jquery1.6版本后attr的变化

發(fā)布時(shí)間:2023/12/9 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Jquery1.6版本后attr的变化 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

原文鏈接:http://www.cnblogs.com/-run/archive/2011/11/16/2251569.html

Jquery1.6版本后attr的變化

Jquery1.6版本后 attr 改動(dòng)后的效果:
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.

elem.checked$(elem).prop("checked")elem.getAttribute("checked")$(elem).attr("checked")(1.6)$(elem).attr("checked")(1.6.1+)$(elem).attr("checked")(pre-1.6)
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 版本:

1 <!DOCTYPE html> 2 <html> 3 <head> 4 <style> 5 p { margin: 20px 0 0 } 6 b { color: blue; } 7 </style> 8 <script src="../js/jquery-1.4.4.js"></script> 9 </head> 10 <body> 11 12 <input id="check1" type="checkbox" checked="checked"> 13 <label for="check1">Check me</label> 14 <p></p> 15 16 <script> 17 $("input").change(function() { 18 var $input = $(this); 19 $("p").html(".attr('checked'): <b>" + $input.attr('checked') + "</b><br>" 20 + ".is(':checked'): <b>" + $input.is(':checked') ) + "</b>"; 21 }).change(); 22 </script> 23 24 </body> 25 </html>

?

勾選后輸出: //attr('checked'): true //.prop('checked') 1.6后版本才有這個(gè)方法 //.is(':checked'): true 取消勾選輸出://.attr('checked'): false //.prop('checked')1.6后版本才有這個(gè)方法 //.is(':checked'): false


?



結(jié)論: attr('checked'): 在1.6后版本,所獲取的值是 "checked"/"underfined"? ,之前所獲得的值是"false"/"true"。截然不同

?

長(zhǎng)知識(shí)了

作者:那瞬間
出處:http://www.cnblogs.com/-run/
本文版權(quán)歸作者和博客園共有,歡迎轉(zhuǎn)載,但未經(jīng)作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責(zé)任的權(quán)利。

總結(jié)

以上是生活随笔為你收集整理的Jquery1.6版本后attr的变化的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。