jQuery length 和 size()区别
生活随笔
收集整理的這篇文章主要介紹了
jQuery length 和 size()区别
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
? jQuery length和size()區別總結如下:
??? 1.length是屬性,size()是方法。
??? 2.如果你只是想獲取元素的個數,兩者效果一樣既 $("img").length 和 $("img").size() 獲取的值是一樣的;但是如果是獲取字符串的長度就只得用length, 如 $("#text").val().length
??? 看看官網的解釋(http://api.jquery.com/size/):
The?.size()?method is deprecated as of jQuery 1.8. Use the?.length?property instead.
The?.size()?method is functionally equivalent to the?.length?property; however,?the?.lengthproperty is preferred?because it does not have the overhead of a function call.
???? jQuery length和size()區別 ?從上可以看出size()是調用length屬性實現的,而且 在jquery 1.8后 length取代了 size()? ,因為length不需要返回一個函數調用,更優秀 。
總結
以上是生活随笔為你收集整理的jQuery length 和 size()区别的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vue2使用axios post跳坑,封
- 下一篇: Javascript面向对象编程:构造函