使用.classList和.togle的Javascript函数在IE8中不起作用
Javascript function which uses .classList and .toggle is not working in IE8
我有一个函数,它只是根据单击来更改元素的类。除了IE8,它在任何地方都能正常工作。任何帮助都将是伟大的!
这就是功能:
function attachToggleReportType (elem) {
elem.addEventListener('change', toggleReportType);
}
function toggleReportType () {
var reportOptions = document.querySelectorAll('.report'),
reportIncToggle = document.querySelectorAll('.toggle');
reportSample({
href: this.getAttribute('data-sample-report-link'),
src: this.getAttribute('data-sample-report-image')
});
reportIncToggle.forEach(toggleInclude);
var report_type = $(this).find('input[type=radio]').val();
report_type = ( report_type == 1 ? 'Verified' : 'Claims');
// analytics.updateType(report_type);
}
function toggleInclude (item) {
item.classList.toggle('notIncluded');
item.classList.toggle('included');
}
HTML
<li class="larger toggle notIncluded">
<span>Cross-Canada lien search</span>
<br>
Exclusive to CARPROOF <strong>Verified</strong> reports, we’ll tell you if there’s money owing on the vehicle.
</li>
看起来您正在使用jQuery,它为在元素上操作类提供了跨浏览器支持。此外,IE 8 中不支持forEach
classList浏览器支持
forEach浏览器支持
jQuery
$('.elementClass').toggleClass('className');
JSFiddle(不带jQuery,支持IE8)
classList
不受IE8或9的支持。由于您已经在使用jQuery
,您应该只使用:jQuery.toggleClass.
$(item).toggleClass('notIncluded included');
相关文章:
- 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>.
- getElementsByTagName和getElementsByClassName在IE8中不起作用
- 导航在IE8上不起作用