jQuery length 和 size()区别

来源:互联网 发布:js获取asp控件的值 编辑:程序博客网 时间:2024/06/06 09:42

  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不需要返回一个函数调用,更优秀
原创粉丝点击