window.onload = function(){
var tab = document.getElementById("tab");
var ul = tab.getElementsByTagName("ul")[0];
var li = ul.getElementsByTagName("li");
var div = tab.getElementsByTagName("div");
for(var i = 0; i < li.length; i++){
li[i].index = i;
li[i].onclick = function(){
for(var n = 0; n < li.length; n++){
li[n].className = "";
div[n].className = "hidden";
}
this.className = "active";
div[this.index].className = "";
}
};
}
有谁给我解释下li[i].index = i;和div[this.index].className = "";这块是什么意思啊????
li[i].index = i;是相当于给元素添加一个index属性. 值就是i的值 ps: <div index="1"></div>
this.index是指获取当前元素上index属性的值.