Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.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/2/jquery/82.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 如何使用or运算符返回值?_Javascript_Jquery_Css - Fatal编程技术网

Javascript 如何使用or运算符返回值?

Javascript 如何使用or运算符返回值?,javascript,jquery,css,Javascript,Jquery,Css,我如何返回或使用如下方法: $('div').filter(function(){ return $(this).index(3) or $(this).index(6); }).css('color','red'); 如果索引(3)是真实的,则以下内容将返回索引(3);否则它将返回索引(6) 如果索引(3)是真实的,则以下内容将返回索引(3);否则它将返回索引(6) 要过滤第四和第七个元素,您需要: $('div').filter(function () { var inde

我如何返回或使用如下方法:

$('div').filter(function(){
    return $(this).index(3) or $(this).index(6);
}).css('color','red');

如果索引(3)是真实的,则以下内容将返回索引(3);否则它将返回索引(6)


如果索引(3)是真实的,则以下内容将返回索引(3);否则它将返回索引(6)


要过滤第四和第七个元素,您需要:

$('div').filter(function () {
    var index = $(this).index();
    return index === 3 || index === 6;
}).css('color', 'red');
要过滤4th、7th、10th、元素,可以编写:

$('div').filter(function () {
    var index = $(this).index();
    return index > 0 && index % 3 === 0;
}).css('color', 'red');
要根据值的白名单进行筛选,可以使用数组文字和:


要过滤第四和第七个元素,您需要:

$('div').filter(function () {
    var index = $(this).index();
    return index === 3 || index === 6;
}).css('color', 'red');
要过滤4th、7th、10th、元素,可以编写:

$('div').filter(function () {
    var index = $(this).index();
    return index > 0 && index % 3 === 0;
}).css('color', 'red');
要根据值的白名单进行筛选,可以使用数组文字和:


可能是第n个子过滤器

$('div').filter(':nth-child(4), :nth-child(7)').css('color','red');

演示:

可能是第n个子过滤器

$('div').filter(':nth-child(4), :nth-child(7)').css('color','red');
演示:

for(变量i=0;i<10;i++){
$('body')。附加(''+i+'')
}
$('div').filter(函数(){
如果($(this.index()=“3”| |$(this.index()=“6”)
{
$(this.css('color','red');
}
});
用于(变量i=0;i<10;i++){
$('body')。附加(''+i+'')
}
$('div').filter(函数(){
如果($(this.index()=“3”| |$(this.index()=“6”)
{
$(this.css('color','red');
}
});

我无法理解>=0正在检查什么。
$。如果未找到搜索的值,inArray
将返回-1;如果在数组中找到搜索值,则返回一个>=0的数字。我无法理解>=0正在检查什么。
$。如果未找到搜索值,则inArray
返回-1;或者,如果在数组中找到搜索值,则数字>=0。@NavinLauniya请参阅-对于索引中的所有元素,如
4,7,10,13…
(索引以1开头)@NavinLauniya请参阅-对于索引中的所有元素,如
4,7,10,13…
(索引以1开头)