怎么沒反應(yīng)??求解釋
<!DOCTYPE html>
<html>
<head>
? ? <meta charset="UTF-8">
? ? <title>實(shí)踐題 - 選項卡</title>
? ? <style type="text/css">
? ? ?/* CSS樣式制作 */ ?
? ? ?.whole{
? ? ? ? ?padding:2px;margin:20px;width:280px;height:180px;
? ? ? ? ?}
? ? ?.noe{list-style:none;display: block;height:30px;line-height:30px;border-bottom:2px solid;}
??
? ? ?.whole div{ ??
? ? ? ? position:absolute;
? ? ? ? border-top:solid red;
? ? ? ? border-bottom:solid blue thin;
? ? ? ? border-left:solid blue thin;
? ? ? ? border-right:solid blue thin;
? ? ? ? width:280px;
? ? ? ? height:180px;?
? ? ? ? line-height:20px;
? ? ? ? padding:5px;
? ? ? ? }
? ? ?.c{?
? ? ? ? display:none;
? ? ? ? }
? ? .whole ul li{
? ? ? ? border:solid red thin;
? ? ? ? border-bottom:none;
? ? ? ? width:60px;
? ? ? ? float:left;
? ? ? ? line-height:28px;
? ? ? ? text-align:center;
? ? ? ? margin:0px 3px;
? ? ? ? display:inline-block;
? ? ? ? cursor:pointer;
? ? }
? ??
? ? ? ?
? ? </style>
? ? <script type="text/javascript">
? ? // JS實(shí)現(xiàn)選項卡切換
? ? window.onload=function(){
? ? var ti=document.getElementsByTagName("whole");
? ? var te=document.getElementsByTagName("ul").[0];
? ? var rui=ti.getElementsByTagName("li");
? ? var du=ti.getElementsByTagName("div");
? ? for(var i=0;i<rui.length;i++){
? ? ? ? rui[i].index=i;
? ? ? ? rui[i].onclick=function(){
? ? ? ? ? ? for(var n=0;n<rui.length;n++){
? ? ? ? ? ? ? ? rui[n].className="";
? ? ? ? ? ? ? ? du[n].className="c"; ? ? ? ? ? ? ??
? ? ? ? ? ? }
? ? ? ? ? ? this.className="tip";
? ? ? ? ? ? du[this.index].className="";
? ? ? ? }
? ? }
? ? </script>
?
</head>
<body>
<!-- HTML頁面布局 -->
<div>
<ul>
<li>房產(chǎn)</li>?
<li >家居</li>
<li >二手房</li>
</ul>
<div >275萬購昌平鄰鐵三居 總價20萬買一居<br>200萬內(nèi)購五環(huán)三居 140萬安家東三環(huán)<br>北京首先零首付樓盤 53萬購東5環(huán)50平<br>京樓盤直降5000 中信府 公園樓王現(xiàn)房</div>
<div>40平出租屋大改造 美少女混搭小窩<br>經(jīng)典清新簡歐愛家 90平老房煥發(fā)新生<br>新中式的酷色溫情 66平撞色活潑家居<br>瓷磚就像選好老婆 衛(wèi)生間煙道的設(shè)計</div>
<div>通州豪華3居260萬 二環(huán)稀缺2居250W甩<br>西3環(huán)通透2居290萬 130萬2居限量搶購<br>皇城根小學(xué)學(xué)區(qū)僅260萬 121平270萬拋!<br>獨(dú)家別墅280萬 蘇州橋2居優(yōu)惠價248萬</div>
</div>
</body>
</html>
2014-12-04
script標(biāo)簽中寫JS代碼有問題,你仔細(xì)看看,右側(cè)有源碼下載可以參考
document.getElementsByTagName("ul").[0];如果你在數(shù)組元素中取元素的話,不用點(diǎn),document.getElementsByTagName("ul").[0];這么寫就行
另外for循環(huán)沒有閉合大括號
whole這是元素名稱嗎?為什么用getElementsByTagName這個方法去獲???