原型函数在IE8中不起作用
Prototype function not working in IE8
我最近问了一个问题,得到了一个有效的工作答案。然而,当时我正在 Firefox 中进行测试,虽然一切看起来都很好,但所需的浏览器 IE8 不喜欢这个功能。
我正试图找到它的替代品。
这是我的原始问题:jQuery 按条件过滤行
这是有效的答案(虽然不是在IE8中):
// collating the 'regions':
var regions = ['americas', 'emea', 'apac'],
// initialising an array to use, later:
foundClasses = [];
// iterating over the 'tr' elements, filtering them:
$('tr').filter(function () {
// using Array.prototype.forEach to filter the classList of the element:
foundClasses = Array.prototype.filter.call(this.classList, function (c) {
// 'c' is the current class in the classList we're iterating over,
// if it's in the array we return that array to the 'foundClasses':
if (regions.indexOf(c) > -1) {
return c;
}
});
// we keep the the element in the jQuery collection (of 'tr' elements),
// if we do not have exactly 2 of the allowed classes...
return foundClasses.length !== 2;
// removing those 'tr' elements:
}).remove();
我对原型知之甚少,所以我只是使用它,因为它满足了我需要的作用,但欢迎任何其他解决方案。
如评论中所述。 IE8 中不存在Array.prototype.filter
。相反,您可以使用jQuery的grep()
:
// collating the 'regions':
var regions = ['americas', 'emea', 'apac'];
// iterating over the 'tr' elements, filtering them:
$('tr').filter(function () {
var foundClasses = $.grep(this.className.split(/'s+/), function (c) {
return $.grep(regions, function(r) { return r === c; }).length > 0;
});
// we keep the the element in the jQuery collection (of 'tr' elements),
// if we do not have exactly 2 of the allowed classes...
return foundClasses.length !== 2;
}).remove();
请注意,在 IE 10 之前,IE 也不支持.classList
。相反,您可以使用 this.className.split(/'s+/)
,如上所述。
相关文章:
- Recaptcha在IE7和IE8中不起作用
- 在IE8中不起作用的元素上触发单击事件
- 数据-在IE8中不起作用
- getComputedStyle替换:currentStyle(IE8/7)不起作用
- IE8 jquery ajax头请求不起作用
- 显示隐藏的html表在javascript(IE8)中不起作用
- ScriptX 打印功能在 IE8 中不起作用
- Angularjs 跨源资源共享 (CORS) 发布或放置方法在 IE8 和 IE9 中不起作用
- ExtJs 5.0:forEach on Array of Objects在IE8中不起作用
- 将JSON对象转换为敲除observable在IE8中不起作用,但在所有其他浏览器中都起作用
- 聚焦函数在ie8中不起作用
- 启动网格在IE8中不起作用
- Svg标签在IE8中不起作用
- Twitter引导程序示例在IE8中不起作用
- 引导程序3在IE8中不起作用(已检查其他答案)
- IE8的Javascript占位符不起作用
- Javascript中的开关案例在IE8中不起作用
- 如果我添加 pageX 页面 Y 在 IE8 中不起作用<!文档类型 html>.
- $.getScript 不起作用 (IE8)
- 点击事件不起作用IE8