Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/375.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 计数元素之间的语法混淆_Javascript_Jquery_Syntax_Counting - Fatal编程技术网

Javascript 计数元素之间的语法混淆

Javascript 计数元素之间的语法混淆,javascript,jquery,syntax,counting,Javascript,Jquery,Syntax,Counting,$(this).sibbines()返回: [<section style class=​"white">​…​</section>​ , <section style class=​"white">​…​</section>​ , <section style=​"display:​ none">​…​</section>​ , <section style=​"display:​ none">​…​</

$(this).sibbines()
返回:

[<section style class=​"white">​…​</section>​
, <section style class=​"white">​…​</section>​
, <section style=​"display:​ none">​…​</section>​
, <section style=​"display:​ none">​…​</section>​
, <section style=​"display:​ none">​…​</section>​
, <section style=​"display:​ none">​…​</section>​
, <section style=​"display:​ none">​…​</section>​]
要查看有多少可见,我需要计算白色的类。过了很长一段时间,我才得以实现这一目标:

var hidden=0;
$(this).siblings().each(function(){
    if ($(this).hasClass('white')) {hidden++;};
});
为什么我必须循环遍历每个兄弟姐妹,而不能使用下面的一行或另一行来计算类为“白色”的兄弟姐妹:

var hidden = ($(this).siblings().filter(':white').length); or
var hidden = ($(this).siblings().filter('white').length);


为什么要经历
.filter()
.hasClass()
.is()
和循环的麻烦呢?还有那些是“白色的”


为什么要经历
.filter()
.hasClass()
.is()
和循环的麻烦呢?还有那些是“白色的”


请张贴你的HTML。或者jsFiddle.TIP:使用
$('.fs.btn.heading.abstract')
不是一个好主意,也就是说,要确定我正在测试的特定元素,我已经编辑过了。为什么这不是一个好主意呢?我是JQuery新手。请发布您的HTML。或者jsFiddle.TIP:使用
$('.fs.btn.heading.abstract')
不是一个好主意,也就是说,要确定我正在测试的特定元素,我已经编辑过了。为什么这不是一个好主意呢?我是JQuery的新手。啊,是的!
表示类别。但是,我不知道您可以将参数传递给兄弟()。我是否也可以在此行中传递“:visible:
var hidden=($(this).sides().filter(“:visible”).length)并将其设置为:
var hidden=($(this).this(':visible').length)?是的。这意味着任何有效的选择器啊,是的!
表示类别。但是,我不知道您可以将参数传递给兄弟()。我是否也可以在此行中传递“:visible:
var hidden=($(this).sides().filter(“:visible”).length)并将其设置为:
var hidden=($(this).this(':visible').length)?是的。这意味着任何有效的选择器
var hidden = ($(this).siblings().filter(':white').length); or
var hidden = ($(this).siblings().filter('white').length);
var hidden = ($(this).siblings().hasClass('white').length);
var hidden = ($(this).siblings().is(':white').length); or
var hidden = ($(this).siblings().is('white').length);
$(this).siblings('.white').length