0

我想计算一些 div 的数量。这是我的页面结构作为图片。我想获得 cityUnderText div 的计数。

在此处输入图像描述

我正在使用这些脚本代码,但我得到0但我只需要6

var h = $("div.cityUnderText").length;
alert(h);

var h = $(".cityUnderText").length;
alert(h);
4

3 回答 3

1

试试$(".cityundertext").length

JavaScript 是一种区分大小写的语言

于 2012-05-05T22:08:08.460 回答
1
var count=$(".cityundertext").size(); // jquery's method

或者

var count=$(".cityundertext").length; 

或者更具体

var count=$("#content_pnlDestinations .cityundertext").size(); // jquery's method

或者

var count=$("#content_pnlDestinations .cityundertext").length; 
于 2012-05-05T22:11:44.167 回答
0

You can use document.querySelectorAll('div > div').length, which is faster than jQuery, because it's native (2x to 3x faster).

于 2012-05-05T22:31:11.757 回答