求問大神。其他都很正常,導(dǎo)入其他切換的js代碼都非常正常的顯示,可是為什么再倒入延時(shí)切換的js代碼以后,我的css樣式就不能正常顯示了呢?導(dǎo)入老師延時(shí)JS代碼也是這樣。(只能顯示標(biāo)題,顯示不了內(nèi)容)這是我的js和css代碼。實(shí)在不知道問題出在了哪里。小白求教。謝謝!
window.onload=function?()?{
????var?index=0;
????var?timer=null;
????var?list=document.getElementById("title").getElementsByTagName("li");
????var?divs=document.getElementById("content").getElementsByTagName("div");
????if(list.length!=divs.length){
????????return;
????}
????for(var?i=0;i<list.length;i++){
????????list[i].id=i;
????????list.onmouseover=function?()?{
????????????var?that=this;
????????????if(timer){
????????????????clearTimeout(timer);
????????????????timer=null;
????????????}
????????????timer=window.setTimeout(function?()?{
????????????????for(var?j=0;j<list.length;j++){
????????????????????list[j].className="";
????????????????????divs.display.style="none";
????????????????}
????????????list[that.id].className="select";
????????????????divs[that.id].display.style="block";
????????????},500);
????????}
????}
}
css代碼:
<!DOCTYPE?html>
<html?lang="en">
<head>
????<meta?charset="UTF-8">
????<title>tabPrac</title>
????<script?src="js/tabyanshi.js"></script>
????<style>
????????*{
????????????margin:?0;
????????????padding:?0;
????????????list-style:?none;
????????????font-size:?12px;
????????}
????????.notice{
????????????width:?298px;
????????????height:?98px;
????????????margin:?0?auto;
????????????border:?1px?solid?#eee;
????????????overflow:?hidden;
????????}
????????.title{
????????????height:?27px;
????????????position:?relative;
????????????background-color:?#f7f7f7;
????????}
????????.title?ul{
????????????position:?absolute;
????????????width:?301px;
????????????left:?-1px;
????????}
????????.title?li{
????????????float:?left;
????????????width:?58px;
????????????height:?26px;
????????????line-height:?26px;;
????????????overflow:?hidden;
????????????text-align:?center;
????????????border-bottom:?1px?solid?#eee;
????????????padding:?0?1px;
????????}
????????.title?li?a{
????????????color:?black;
????????????text-decoration:?none;
????????}
????????.title?li.select{
????????????background:?white;
????????????border-bottom-color:white;
???????????border-left:1px?solid?#eee;
????????????border-right:1px?solid?#eee;
????????????padding:?0px;
????????????font-weight:?bold;
????????}
????????.title?li?a:hover{
????????????color:?silver;
????????}
????????.mod{
????????????margin:?10px?10px?10px?19px;
????????}
????????.mod?ul?li{
????????????float:?left;
????????????width:?134px;
????????????height:?25px;
????????????overflow:?hidden;
????????}
????</style>
</head>
<body>
<div?id="notice"?class="notice">
????<div?id="title"?class="title">
????????<ul>
????????????<li><a?href="#">公告</a></li>
????????????<li><a?href="#">規(guī)則</a></li>
????????????<li><a?href="#">論壇</a></li>
????????????<li><a?href="#">安全</a></li>
????????????<li?class="select"><a?href="#">公益</a></li>
????????</ul>
????</div>
????<div?id="content"?class="content">
????????<div?class="mod"?style="display:?none">
????????<ul>
????????????<li><a?href="#">孫建華當(dāng)選呼和</a></li>
????????????<li><a?href="#">?賈英祥不再擔(dān)任</a></li>
????????????<li><a?href="#">?網(wǎng)絡(luò)主播直播算命</a></li>
????????????<li><a?href="#">?江西要求全省公車</a></li>
????????</ul>
????</div>
????????<div?class="mod"?style="display:?none">
????????????<ul>
????????????????<li><a?href="#">全國第4個(gè)省份</a></li>
????????????????<li><a?href="#">?法國總理卡澤</a></li>
????????????????<li><a?href="#">??武漢一日游都去哪了</a></li>
????????????????<li><a?href="#">?湖北評出2016年</a></li>
????????????</ul>
????????</div>
????????<div?class="mod"?style="display:?none">
????????????<ul>
????????????????<li><a?href="#">全省份</a></li>
????????????????<li><a?href="#">?首次訪華</a></li>
????????????????<li><a?href="#">??武漢一日游</a></li>
????????????????<li><a?href="#">?湖北評十大科</a></li>
????????????</ul>
????????</div>
????????<div?class="mod"?style="display:?none">
????????????<ul>
????????????????<li><a?href="#">國民黨選舉殺</a></li>
????????????????<li><a?href="#">?女黑馬”?洪秀柱</a></li>
????????????????<li><a?href="#">去年凍結(jié)74萬個(gè)?</a></li>
????????????????<li><a?href="#">?2016年度十大科</a></li>
????????????</ul>
????????</div>
????????<div?class="mod"?style="display:?none">
????????????<ul>
????????????????<li><a?href="#">網(wǎng)貸存管指</a></li>
????????????????<li><a?href="#">?超九成P2P</a></li>
????????????????<li><a?href="#">影院放映廳安?</a></li>
????????????????<li><a?href="#">律師:未侵犯隱私</a></li>
????????????</ul>
????????</div>
????</div>
</div>
</body>
</html>
2018-07-18
親我剛了你的代碼雖然這么晚了而且時(shí)間過了這么久!但還是來回答一下您的問題
開始的時(shí)候你所有的內(nèi)容都隱藏掉了,您應(yīng)該顯示一個(gè)
2017-02-25
首先你的id命名有問題,開頭不能是數(shù)字;
其它的,你自己好好整理一下自己的思路吧;多想想多做
2017-02-25
給你個(gè)建議,你這樣問問題,幾乎不會(huì)有人愿意回答的;
你最好把所有的代碼都粘貼上,不然還有推算你的div結(jié)構(gòu)和命名,這......,太虐心了