使用jQuery将具有类的所有对象加载到数组中 [英] Loading all objects with class into an array using jQuery

查看:57
本文介绍了使用jQuery将具有类的所有对象加载到数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面上有一堆类为testClass的div.

I have a bunch of div's on my page with class testClass.

我想将它们加载到数组中,然后检查数组的大小.

I want to load them into an array and then check the array's size.

但是它不起作用吗?

myArray = $('testClass');

alert(myArray.count);

怎么了?

推荐答案

您拥有:

myArray = $('testClass');
alert(myArray.count);

您想要:

myArray = $('.testClass');
alert(myArray.length);

请注意,首先是.用于testClass. 然后,myArray是一个JavaScript对象,因此您可以访问length键.

Notice, first, the . for testClass. Then, myArray is a JavaScript object, so you have access to the length key.

这篇关于使用jQuery将具有类的所有对象加载到数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆