我的页面中有$myVars = $this->getArrayOfVars();
$var1 = $myDB->getVar1();// could be null or ""
$var2 = $myDB->getVar2();// could be null or ""
if ((!empty($var1) && $var1 == $myVars[1]) || (!empty($var2) && $var2 == $myVars[2])) {
//do stuff
// I just enter here when the strings are equal, but avoiding the null or empty values
}
的几个元素。如何通过这些元素执行循环?
类似的东西:
position: fixed
答案 0 :(得分:1)
您可以使用filter
:
$('*').filter(function() {
return $(this).css("position") === 'fixed';
});
该函数将遍历每个元素并检查要满足的条件。如果是fixed
,则返回true
。 filter()
函数是$()
选择器的附加组件,仅选择满足条件的元素。
如果上述方法不起作用,您也可以使用:
$('*').filter(function () {
return this.style && this.style.position === 'fixed'
});
上述代码的原因:
.css()
是jQuery的函数,它适用于jQuery对象。从本机对象创建jQuery对象,并在jQuery对象上运行jQuery函数可能比本机函数耗时且性能密集。