課程
/前端開發
/JavaScript
/JavaScript進階篇
加油啦啦啦啦啦~
2015-01-12
源自:JavaScript進階篇 9-10
正在回答
<!DOCTYPE html>
<html>
<head>
? ? <meta charset="UTF-8">
? ? <title>實踐題 - 選項卡</title>
? ? <style type="text/css">
? ? ?/* CSS樣式制作 */ ?
?*{
? ? margin:0px; padding:0px; font:12px normal; font-family:微軟雅黑;
? ? } ? ? ??
?#tit{
? ? ?width:290px; height:150px; padding:5px; margin:20px;
?}
?#tit ul{
? ? ?list-style:none; display:block; height:30px; line-height:30px;
?#tit ul li{
? ? ?float:left; width:60px; height:28px; line-height:28px; text-align:center;
? ? ?display:inline-block;margin:0px 3px; border:1px solid #aaa;border-bottom:none;
? ? ?cursor:pointer; background:#fff; list-style:none;
?#tit ul li.lis{
? ? ?border-top:2px solid saddlebrown; border-bottom:2px solid #fff;
?#tit div{
? ? ?height:120px; line-height:25px; border:1px solid #336699;border-top:2px saddlebrown solid;padding:5px;
?.hide{display:none;}?
? ? ? ?
? ? </style>
? ? <script type="text/javascript">
? ? ? ? ?
? ? // JS實現選項卡切換
? ? ?window.onload=function(){
? ? ? ? var tits=document.getElementsByTagName("li");
var divparent= document.getElementById("tit");
? ? ? ? var divs=divparent.getElementsByTagName("div");
? ? ? ??
? ? ? ? for(var i=0;i<tits.length;i++){
? ? ? ? ? ? tits[i].index = i;?
? ? ? ? ? ? tits[i].onmouseover = function(){
? ? ? ? ? ? for(var n=0;n<tits.length;n++){
? ? ? ? ? ? ? ? tits[n].className = "";
? ? ? ? ? ? ? ? divs[n].className = "hide";
? ? ? ? ? ? }
? ? ? ? ? ? this.className = "lis";
? ? ? ? ? ? divs[this.index].className ="";
? ? ? ? }
? ? }
? ??
? ? </script>
?
</head>
<body>
<!-- HTML頁面布局 -->
<div id="tit">
? ? <ul>
? ? ? ? <li>房產</li>
? ? ? ? <li>家居</li>
? ? ? ? <li>二手房</li>
? ? </ul>
? ? <div>
? ? 275萬購昌平鄰鐵三居 總價20萬買一居<br>
? ? 200萬內購五環三居 140萬安家東三環<br>
? ? 北京首現零首付樓盤 53萬購東5環50平<br>
? ? 京樓盤直降5000 中信府 公園樓王現房<br>
? ? </div>
? ? ?40平出租屋大改造 美少女的混搭小窩<br>
? ? ?經典清新簡歐愛家 90平老房煥發新生<br>
? ? ?新中式的酷色溫情 66平撞色活潑家居<br>
? ? ?瓷磚就像選好老婆 衛生間煙道的設計<br>
? ? ?通州豪華3居260萬 二環稀缺2居250w甩<br>
? ? ?西3環通透2居290萬 130萬2居限量搶購<br>
? ? ?黃城根小學學區僅260萬 121平70萬拋!<br>
? ? ?獨家別墅280萬 蘇州橋2居優惠價248萬<br>
</div>
</body>
</html>
舉報
本課程從如何插入JS代碼開始,帶您進入網頁動態交互世界
1 回答就這樣子啦
1 回答一行就搞定啦
1 回答完成了啦啦啦啦
1 回答完成啦啦啦
2 回答界面變成這樣了,顯示結果沒啦
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2016-01-02
<!DOCTYPE html>
<html>
<head>
? ? <meta charset="UTF-8">
? ? <title>實踐題 - 選項卡</title>
? ? <style type="text/css">
? ? ?/* CSS樣式制作 */ ?
?*{
? ? margin:0px; padding:0px; font:12px normal; font-family:微軟雅黑;
? ? } ? ? ??
?#tit{
? ? ?width:290px; height:150px; padding:5px; margin:20px;
?}
?#tit ul{
? ? ?list-style:none; display:block; height:30px; line-height:30px;
?}
?#tit ul li{
? ? ?float:left; width:60px; height:28px; line-height:28px; text-align:center;
? ? ?display:inline-block;margin:0px 3px; border:1px solid #aaa;border-bottom:none;
? ? ?cursor:pointer; background:#fff; list-style:none;
?}
?#tit ul li.lis{
? ? ?border-top:2px solid saddlebrown; border-bottom:2px solid #fff;
?}
?#tit div{
? ? ?height:120px; line-height:25px; border:1px solid #336699;border-top:2px saddlebrown solid;padding:5px;
?}
?.hide{display:none;}?
? ? ? ?
? ? </style>
? ? <script type="text/javascript">
? ? ? ? ?
? ? // JS實現選項卡切換
? ? ?window.onload=function(){
? ? ? ? var tits=document.getElementsByTagName("li");
var divparent= document.getElementById("tit");
? ? ? ? var divs=divparent.getElementsByTagName("div");
? ? ? ??
? ? ? ? for(var i=0;i<tits.length;i++){
? ? ? ? ? ? tits[i].index = i;?
? ? ? ? ? ? tits[i].onmouseover = function(){
? ? ? ? ? ? for(var n=0;n<tits.length;n++){
? ? ? ? ? ? ? ? tits[n].className = "";
? ? ? ? ? ? ? ? divs[n].className = "hide";
? ? ? ? ? ? }
? ? ? ? ? ? this.className = "lis";
? ? ? ? ? ? divs[this.index].className ="";
? ? ? ? ? ? }
? ? ? ? }
? ? }
? ??
? ??
? ? </script>
?
</head>
<body>
<!-- HTML頁面布局 -->
<div id="tit">
? ? <ul>
? ? ? ? <li>房產</li>
? ? ? ? <li>家居</li>
? ? ? ? <li>二手房</li>
? ? </ul>
? ? <div>
? ? 275萬購昌平鄰鐵三居 總價20萬買一居<br>
? ? 200萬內購五環三居 140萬安家東三環<br>
? ? 北京首現零首付樓盤 53萬購東5環50平<br>
? ? 京樓盤直降5000 中信府 公園樓王現房<br>
? ? </div>
? ? <div>
? ? ?40平出租屋大改造 美少女的混搭小窩<br>
? ? ?經典清新簡歐愛家 90平老房煥發新生<br>
? ? ?新中式的酷色溫情 66平撞色活潑家居<br>
? ? ?瓷磚就像選好老婆 衛生間煙道的設計<br>
? ? </div>
? ? <div>
? ? ?通州豪華3居260萬 二環稀缺2居250w甩<br>
? ? ?西3環通透2居290萬 130萬2居限量搶購<br>
? ? ?黃城根小學學區僅260萬 121平70萬拋!<br>
? ? ?獨家別墅280萬 蘇州橋2居優惠價248萬<br>
? ? </div>
</div>
?
</body>
</html>