一般把script放在body的最下方就可以获开到body里的元素了,可是我做的这个选项卡效果把script放在body的最下面了,可是去掉window.onload之后,效果就出不来了,这是怎么回事 Title *{ margin:0; padding:0; list-style-type: none; } #container{ width:400px; height:250px; position: relative; } #top li{ width:100px; height:50px; float: left; } #bottom li{ width:400px; height:200px; position: absolute; left:0; top:50px; display: none; } .first{ background: red; } .second{ background: blue; } .third{ background: purple; } .four{ background: pink; } #bottom li.first{ display: block; }
<script> window.onload= function () { var top = document.getElementById("top"), top_li = top.getElementsByTagName("li"), bottom = document.getElementById("bottom"), bottom_li = bottom.getElementsByTagName("li"); for (var i = 0; i |