我有一个未完成/退出的嵌套 for 循环它卡在第二个循环中:
for (var j = 0; next.className != "rfccs" && next !== null; j++)
仅当“下一个”为空时才会卡住。
我的代码:
var filtertypes = document.getElementsByClassName("rfccs"); // filtertypes is an array of all filter type headers
var next = null; // placeholder for the next sibling element
var tout = document.getElementById("testout"); //test
tout.innerHTML = "init "; //test
for (var i = 0; i < filtertypes.length; i++) {
filtertypes[i].className += " fhead" + i; // adds a unique class to every filter type header div
var filtertype = filtertypes[i]; // sets filtertype to the current filter type header
next = filtertype.nextElementSibling; // gets the next sibling
for (var j = 0; next.className != "rfccs" && next !== null; j++) { // adds the same class name to all filters in the same filter type
next.className += " ftype" + i;
next.innerHTML += i;
next = next.nextElementSibling;
tout.innerHTML += "i = " + i + "; j = " + j + "///";
if (next == null) {
tout.innerHTML += "DONE";
}
}
tout.innerHTML += "~~~~";
}
我知道我的跟踪/调试代码真的很乱。
这是小提琴