Bài viết phổ biến của tác giả
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这里,为什么我的代码在 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",'Previous');
timeline.insertAdjacentHTML('afterbegin','Next');
}
}
$(document).on ('click','.prev',function() {
let select = $(this).parent();
let totChild = select.children("section");
for(let i=0;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');
}
} khác {
select.children(".prev").hide();
}
});
$(document).on ('click','.next',function() {
let select = $(this).parent();
let totChild = select.children("section");
for(let i=0;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');
}
} khác {
select.children(".next").hide();
}
});
1 Câu trả lời
cho-của
IE 不支持。您可以将 for-of-loop 替换为 jquery 的 each
BẰNG
$("[type=slideshow] section").addClass('hide');
$("[type=slideshow]").each( function(i,ele){ //i is the index and ele is the element in iteration
$(ele).children("section:first").removeClass("hide").addClass('active');
});
此外,无需将 jquery 与 javascript 混合 Bộ chọn truy vấn
并使用 for 循环循环结果。
当使用基于#的选择器#slide
时,如本行所示
var divSlide = document.querySelectorAll('#slide');
它只会给出一个结果,只需使用
timeline = $( "#slide" )[0];
不需要外部for循环Vàif条件.
关于javascript - 使用 JavaScript 使用 FOR OF 数组循环时出现错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49728906/
Tôi là một lập trình viên xuất sắc, rất giỏi!