coffeescript -数组过滤不工作
coffeescript - Array filtering not working
我试图获得一个数组,只有具有背景图像属性的元素,但是,我的代码不工作,我不知道出了什么问题。
elements = document.getElementsByTagName("*")
[].filter.call elements, (el) =>
if el.currentStyle
return el.currentStyle['backgroundImage'] isnt 'none'
else if window.getComputedStyle
return document.defaultView.getComputedStyle(el,null).getPropertyValue('background-image') isnt 'none'
根据javascript文档,
filter()
方法创建一个包含所有通过所提供函数实现的测试的元素的新数组。
所以你需要在使用它之前存储你的过滤数组:
elements = document.getElementsByTagName("*")
filteredElements = [].filter.call elements, (el) =>
if el.currentStyle
return el.currentStyle['backgroundImage'] isnt 'none'
else if window.getComputedStyle
return document.defaultView.getComputedStyle(el,null).getPropertyValue('background-image') isnt 'none'
// filteredElements is your new array with the filtered elements.
相关文章:
- 有可能过滤来自嵌入式YouTube的声音吗
- Javascript:selenium Web驱动程序isDisplayed()不工作
- jQuery UI自动完成突然停止工作
- 通过ID工作进行ng重复跟踪,如何在ng重复中过滤
- 节点阵列过滤不工作
- ExtJs组合过滤不能正常工作
- 过滤收集后,后网分页器不工作
- 数据表过滤&行高亮不能一起工作
- 过滤一个geojson层在传单不工作
- 基本的Javascript过滤函数在Angular2中不能正常工作
- 谷歌地图标记类别过滤不工作
- Javascript在数据表过滤或分页之后不工作
- Chrome扩展WebRequest过滤tabId不工作
- Angular通过friends内部的friend.brand.id进行过滤可以工作,但不能使用'undefin
- 如何在不移动过滤功能的情况下将一组过滤后的数据移动到另一个工作表
- AngularJS的过滤在1.5版本中不能正常工作
- 使用javascript过滤Telerik MVC网格不能与自定义绑定一起工作
- MVC4 Devexpress排序,分组和过滤不工作
- coffeescript -数组过滤不工作
- 为什么jQuery's:可见选择器在过滤时工作方式不同