【发布时间】:2018-04-09 17:04:10
【问题描述】:
在这里,为什么我的代码不能在 IE 中运行。 我的代码适用于所有浏览器。没有问题。 但是当我在 IE 上运行我的项目时,它发现错误。
还有我的 jquery 类和 insertadjacentHTMl 不工作。
我在这段代码中发现的主要问题。
$("[type=slideshow] section").addClass('hide');
for(let ele of Array.from($("[type=slideshow]"))){
$(ele).children("section:first").removeClass("hide").addClass('active');
}
这里是我的代码,请查看错误在哪里。
//Code for Slideshow
var divSlide = document.querySelectorAll('#slide');
var myNodeList = divSlide.length;
let slideNo = 1;
for(var i = 0; i < myNodeList; i++) {
var type = divSlide[i].getAttribute("type");
if (type == "timeline") {
} else if (type == "slideshow") {
var timeline = divSlide[i];
let sliderData = timeline.getElementsByTagName("section");
$("[type=slideshow] section").addClass('hide');
for(let ele of Array.from($("[type=slideshow]"))){
$(ele).children("section:first").removeClass("hide").addClass('active');
}
timeline.insertAdjacentHTML("afterbegin",'<a class="left prev color_arrow carousel-control" href="#myCarousel" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span><span class="sr-only">Previous</span></a>');
timeline.insertAdjacentHTML('afterbegin','<a class="right next color_arrows carousel-control" href="#myCarousel" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span><span class="sr-only">Next</span></a>');
}
}
$(document).on ('click','.prev',function() {
let select = $(this).parent();
let totChild = select.children("section");
for(let i=0;i<totChild.length;i++){
if(totChild[i].getAttribute('class').indexOf('active')!=-1){
slideNo=i+1;
}
}
totChild.children('br').remove();
let current = select.children('.active');
let prevEl = current.prev('section');
if(slideNo === totChild.length || slideNo > 1){
select.children(".next").show();
if(prevEl.length !== 1){
prevEl = current.prev().prev();
current.removeClass('active');
current.addClass('hide');
prevEl.addClass('active');
prevEl.addClass('animated');
prevEl.addClass('fadeInLeft');
prevEl.removeClass('hide');
}
} else {
select.children(".prev").hide();
}
});
$(document).on ('click','.next',function() {
let select = $(this).parent();
let totChild = select.children("section");
for(let i=0;i<totChild.length;i++){
if(totChild[i].getAttribute('class').indexOf('active')!=-1){
slideNo=i+1;
}
}
totChild.children('br').remove();
let current = select.children('.active');
let prevEl = current.next('section');
if(slideNo ===1 || slideNo < totChild.length){
select.children(".prev").show();
if(prevEl.length !== 1){
prevEl = current.next().next();
current.removeClass('active');
current.addClass('hide');
prevEl.addClass('animated');
prevEl.addClass('fadeInRight');
prevEl.addClass('active');
prevEl.removeClass('hide');
}
} else {
select.children(".next").hide();
}
});
【问题讨论】:
-
IE 的错误到底是什么?
-
:预期为 ';'这是在 console.log 中显示的
-
那是因为
for..of在IE中完全不支持:developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… -
为什么不使用 jquery 的
each迭代$("[type=slideshow]")? -
@gurvinder372 因为我有 4 个 div,除了 type=timeline 和 slidehsow 和我循环遍历 div 内的所有部分或输入 div 之外,一切都相同。所以我使用每个 $("[type=slideshow]").给我一些建议gurvinder pajji。
标签: javascript jquery html internet-explorer