var oUl = oTab.getElementsByTagName("ul")[0];在这里为什么有[0]呢,不就有一个ul吗
<script type="text/javascript"> window.onload = function(){ var oTab = document.getElementById("tabs"); var oUl = oTab.getElementsByTagName("ul")[0]; var oLis = oUl.getElementsByTagName("li"); var oDivs= oTab.getElementsByTagName("div"); for(var i= 0,len = oLis.length;i<len;i++){ oLis[i].index = i; oLis[i].onclick = function() { for(var n= 0;n<len;n++){ oLis[n].className = ""; oDivs[n].className = "hide"; } this.className = "on"; oDivs[this.index].className = ""; } }; } </script>
var oUl = oTab.getElementsByTagName("ul")[0];在这里为什么有[0]呢,不就有一个ul吗