所有这些方式有什么区别?
//1 $('div').eq(index) //2 $('div')[index] //3 $($('div')[index] ) //4 $('div').get(1)
它们一样吗?
解决方法
没有.
第一个和第三个返回jQuery对象,而第二个和第四个返回DOM元素:
$("div").eq(index) === $($("div")[index]); // --> jQuery object $("div")[index] === $("div").get(index); // --> DOM element
你可以在这里阅读最后一个案例:http://api.jquery.com/get/.
如果您需要查看类型之间的差异,可以尝试在控制台中运行以下命令:
Object.prototype.toString.call($("div").eq(index)); // "[object Object]" Object.prototype.toString.call($("div")[index]); // "[object HTMLDivElement]"