我有一个 javascript 变量来缓存选择器,例如:
var listOfDefferedElements = $('div [id^="Defer"]');
在调试视图中,我看到该列表具有类似于以下的数据:
listOfDefferedElements =
[
<div id="DeferRed-1" class="Red Defer" title="Defer">&nbsp;</div>,
<div id="DeferGreen-3" class="Green Defer" title="Deffered">&nbsp;</div>,
<div id="DeferGreen-4" class="Green Defer" title="Defer">&nbsp;</div>,
<div id="DeferBlue-6" class="Blue Defer" title="Defer">&nbsp;</div>,
<div id="DeferBlue-7" class="Blue Defer" title="Defer">&nbsp;</div>,
<div id="DeferBlue-8" class="BlueDefer" title="Deffered">&nbsp;</div>,
<div id="DeferBlue-9" class="Blue Defer" title="Defer">&nbsp;</div>
]
我想知道如何使用存储过滤条件的变量按类进一步过滤
var filter = "Blue"
在变量中需要这样的输出,最后我应该能够更改类“延迟”->“删除”。感谢任何帮助。
listOfFilteredElements =
[
<div id="DeferBlue-6" class="Blue Defer" title="Defer">&nbsp;</div>,
<div id="DeferBlue-7" class="Blue Defer" title="Defer">&nbsp;</div>,
<div id="DeferBlue-8" class="Blue Defer" title="Deffered">&nbsp;</div>,
<div id="DeferBlue-9" class="Blue Defer" title="Defer">&nbsp;</div>
]
直到现在我试过这个,它过滤包含类“蓝色”的选择器:
var listOfFilteredElements = _.filter(listOfDefferedElements, function(elem){
return (elem.className).indexOf('Blue') >= 0;
});
现在我可以有一个语句来更改/更新其中所有元素的类吗?