jQuery:array zero vs function get zero:[0] vs get(0)

有没有什么理由我应该使用$(‘#x> div’).get(1)当我可以而不是使用$(‘#x> div’)[1]?有差别吗

解决方法

不,没有区别. jQuery包含数组中的所有DOM节点.

$().get(1)=== $()[1]

–jQuery源代码片段 –

get: function( num ) {
    return num == null ?
        // Return a 'clean' array
        this.toArray() :

        // Return just the object
        ( num < 0 ? this[ this.length + num ] : this[ num ] );
},

可以看到,没有参数的.get()将返回所有节点作为数组.这不能用括号来完成.

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...