Skip to content

Commit

Permalink
Fixed div nesting issues when change menu
Browse files Browse the repository at this point in the history
The old method uses js to foreach all the div contents and change each page by changing them. This would cause order problem when there is div nested in another.
New method takes only the closest child of div by JQuery children() method and store into the myTab variable. This solves this issue and makes the code much tidier.
  • Loading branch information
mihane-ichinose authored Aug 6, 2019
1 parent 091d68b commit f7b3299
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ <h3>当前时间:
var myTab = document.getElementById("tab"); //整个div
var myUl = myTab.getElementsByTagName("ul")[0];//一个节点
var myLi = myUl.getElementsByTagName("li"); //数组
var myDiv = myTab.getElementsByTagName("div"); //数组
var myDiv = $(myTab).children('div').get(); //数组

for (var i = 0; i < myLi.length; i++) {
myLi[i].index = i;
Expand All @@ -193,17 +193,10 @@ <h3>当前时间:
document.getElementById("searchID").value = "";
document.getElementById("searchName").value = "";
for (var j = 0; j < myLi.length; j++) {
myLi[j].className = "menu off";
//特殊情况:搜索中带有嵌套的div。
if (j === 2) {
j += 1;
}
myLi[j].className = "menu off";
myDiv[j].className = "hide";
}
this.className = "menu on";
if (this.index === 2) {
this.index += 1;
}
myDiv[this.index].className = "show";
}
}
Expand Down Expand Up @@ -358,4 +351,4 @@ <h3>当前时间:
}
</script>
</body>
</html>
</html>

0 comments on commit f7b3299

Please sign in to comment.