為什么點(diǎn)擊以后沒(méi)有切換啊
<!DOCTYPE html>
<html>
<head>
? ? <meta charset="UTF-8">
? ? <title>實(shí)踐題 - 選項(xiàng)卡</title>
? ? <style type="text/css">
? ? ?/* CSS樣式制作 */ ?
? ? ? ? li{ background:#fff;
? ? ? ? ? ? cursor:pointer;
? ? ? ? ? ? border: 2px solid gray;
? ? ? ? ? ? float:left;
? ? ? ? ? ? height:28px;
? ? ? ? ? ? line-height:28px;
? ? ? ? ? ? list-style:none;
? ? ? ? ? ? margin:0 10px;
? ? ? ? ? ? padding:0 5px;
? ? ? ? ? ? position:relative;
? ? ? ? ? ? left:40%;
? ? ? ? } ??
? ? ? ? ul{ display:block;
? ? ? ? ? ? height:30px;
? ? ? ? ? ? line-height:30px;
? ? ? ? ? ? border-bottom:2px saddlebrown solid; ?
? ? ? ? }
? ? ? ? .hide{
? ? ? ? ? display:none;
? ? ? ? }
? ? ? ? .show{
? ? ? ? ? display:block;
? ? ? ? ? width:300px;
? ? ? ? ? margin:0 38%;
? ? ? ? ? text-align:center;
? ? ? ? ? line-height:25px;
? ? ? ? ? border:2px solid red;
? ? ? ? }
? ? </style>
? ? <script type="text/javascript">
? ? // JS實(shí)現(xiàn)選項(xiàng)卡切換
? ? function monfocus1(){
? ? ? ? var fi=getElementById("first");
? ? ? ? var sec=getElementById("second");
? ? ? ? var thi=getElementById("third");
? ? ? ? fi.className="show";
? ? ? ? sec.className="hide";
? ? ? ? thi.className="hide";
? ? }
? ? function monfocus2(){
? ? ? ? var fi=getElementById("first");
? ? ? ? var sec=getElementById("second");
? ? ? ? var thi=getElementById("third");
? ? ? ? fi.className="hide";
? ? ? ? sec.className="show";
? ? ? ? thi.className="hide";
? ? }
? ? function monfocus3(){
? ? ? ? var fi=getElementById("first");
? ? ? ? var sec=getElementById("second");
? ? ? ? var thi=getElementById("third");
? ? ? ? fi.className="hide";
? ? ? ? sec.className="hide";
? ? ? ? thi.className="show";
? ? }
? ??
? ? </script>
?
</head>
<body>
<!-- HTML頁(yè)面布局 -->
? ? <ul>
? ? ? ? <li onClick="monfocus1()">房產(chǎn)</li>
? ? ? ? <li onClick="monfocus2()">家居</li>
? ? ? ? <li onClick="monfocus3()">二手房</li>
? ? </ul>
? ? <div id="first">
? ? ? ? ? ? 275萬(wàn)購(gòu)昌平鄰鐵三居 總價(jià)20萬(wàn)買(mǎi)一居<br/>
? ? ? ? ? ? 200萬(wàn)內(nèi)購(gòu)五環(huán)三居 140萬(wàn)安家東三環(huán)<br/>
? ? ? ? ? ? 北京首現(xiàn)零首付樓盤(pán) 53萬(wàn)購(gòu)東5環(huán)50平<br/>
? ? ? ? ? ? 京樓盤(pán)直降5000 中信府 公園樓王現(xiàn)房<br/>
? ? </div>
? ? <div id="second">
? ? ? ? ? ? 40平出租屋大改造 美少女的混搭小窩<br />
? ? ? ? ? ? 經(jīng)典清新簡(jiǎn)歐愛(ài)家 90平老房煥發(fā)新生<br />
? ? ? ? ? ? 新中式的酷色溫情 66平撞色活潑家居<br />
? ? ? ? ? ? 瓷磚就像選好老婆 衛(wèi)生間煙道的設(shè)計(jì)<br />
? ? </div>
? ? <div id="third">
? ? ? ? ? ? 通州豪華3居260萬(wàn) 二環(huán)稀缺2居250w甩<br />
? ? ? ? ? ? 西3環(huán)通透2居290萬(wàn) 130萬(wàn)2居限量搶購(gòu)<br />
? ? ? ? ? ? 黃城根小學(xué)學(xué)區(qū)僅260萬(wàn) 121平70萬(wàn)拋!<br />
? ? ? ? ? ? 獨(dú)家別墅280萬(wàn) 蘇州橋2居優(yōu)惠價(jià)248萬(wàn)<br />
? ? </div>
?
</body>
</html>
2017-10-30
1.把你的js代碼放到</body>標(biāo)簽前。2.使用window.onload();造成這種問(wèn)題的原因是瀏覽器自上而下進(jìn)行渲染,執(zhí)行。js代碼執(zhí)行時(shí)元素還沒(méi)加載
2017-10-24
是 document.getElementById() 你漏了document.