課程
/前端開發(fā)
/JavaScript
/JavaScript進階篇
最后執(zhí)行的好怪呀
2019-06-05
源自:JavaScript進階篇 10-1
正在回答
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>實踐題 - 選項卡</title>
<style type="text/css">
/* CSS樣式制作 */ ?
*{margin:0;padding:0;}
ul{list-style: none;}
.box{position: relative;}
.box li{
position:absolute;
top:-33px;
border:1px solid #ccc;
float: left;
padding:5px 20px 5px 20px;
margin:1px 3px 0;
background-color:white;
border-bottom:2px solid brown;
z-index: -1;
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
-khtml-user-select: none;
user-select: none;
}
.box li:hover{
cursor:pointer
.box .tit1{left:0;}
.box .tit2{left:80px;}
.box .tit3{left:160px;}
.context{
width:330px;
clear:both;
padding:5px 0 40px 5px;
border:1px solid blue;
border-top:2px solid brown;
margin-top:33px;
.context ul{
display: none;
.context ul li{
font-size: 14px;
line-height: 25px;
#activated{
display: block;
#act{
height:22px;
border-bottom:none;
z-index: 2;
</style>
<script type="text/javascript">
var page = 1,
box = null,
context = null;
// JS實現(xiàn)選項卡切換
window.onload = function(){
box = document.getElementsByClassName("box")[0]
context = document.getElementsByClassName("context")[0]
function change(i){
context.childNodes[page].setAttribute('id',' ');
context.childNodes[i].setAttribute('id','activated');
box.childNodes[page].setAttribute('id',' ');
box.childNodes[i].setAttribute('id','act');
page = i
</script>
</head>
<body>
<!-- HTML頁面布局 -->
<ul class="box">
<li class="tit1" id="act" onclick="change(1)">房產(chǎn)</li>
<li class="tit2" onclick="change(3)">家居</li>
<li class="tit3" onclick="change(5)">二手房</li>
</ul>
<div class="context">
<ul id="activated">
<li>275萬購昌平鄰鐵三居 總價20萬買一居</li>
<li>200萬內(nèi)購五環(huán)三居 140萬安家東三環(huán)</li>
<li>北京首現(xiàn)零首付樓盤 53萬購東5環(huán)50平</li>
<li>京樓盤直降5000 中信府 公園樓王現(xiàn)房</li>
<ul >
<li>40平出租屋大改造 美少女的混搭小窩</li>
<li>經(jīng)典清新簡歐愛家 90平老房煥發(fā)新生</li>
<li>新中式的酷色溫情 66平撞色活潑家居</li>
<li>瓷磚就像選好老婆 衛(wèi)生間煙道的設(shè)計</li>
<li>通州豪華3居260萬 二環(huán)稀缺2居250w甩</li>
<li>西3環(huán)通透2居290萬 130萬2居限量搶購</li>
<li>黃城根小學(xué)學(xué)區(qū)僅260萬 121平70萬拋!</li>
<li>獨家別墅280萬 蘇州橋2居優(yōu)惠價248萬</li>
</div>
</body>
</html>
我是這么寫的…感覺我寫的好多沒用的…
舉報
本課程從如何插入JS代碼開始,帶您進入網(wǎng)頁動態(tài)交互世界
1 回答大佬們看看問題在哪?
3 回答大佬們看看這樣問題出在哪里
3 回答大佬幫忙看看問題在哪
2 回答大佬們幫我看看這段代碼
1 回答大佬們,這哪有問題....
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2019-06-26
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>實踐題 - 選項卡</title>
<style type="text/css">
/* CSS樣式制作 */ ?
*{margin:0;padding:0;}
ul{list-style: none;}
.box{position: relative;}
.box li{
position:absolute;
top:-33px;
border:1px solid #ccc;
float: left;
padding:5px 20px 5px 20px;
margin:1px 3px 0;
background-color:white;
border-bottom:2px solid brown;
z-index: -1;
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
-khtml-user-select: none;
user-select: none;
}
.box li:hover{
cursor:pointer
}
.box .tit1{left:0;}
.box .tit2{left:80px;}
.box .tit3{left:160px;}
.context{
width:330px;
clear:both;
padding:5px 0 40px 5px;
border:1px solid blue;
border-top:2px solid brown;
margin-top:33px;
}
.context ul{
display: none;
}
.context ul li{
font-size: 14px;
line-height: 25px;
}
#activated{
display: block;
}
#act{
height:22px;
border-top:2px solid brown;
border-bottom:none;
z-index: 2;
}
</style>
<script type="text/javascript">
var page = 1,
box = null,
context = null;
// JS實現(xiàn)選項卡切換
window.onload = function(){
box = document.getElementsByClassName("box")[0]
context = document.getElementsByClassName("context")[0]
}
function change(i){
context.childNodes[page].setAttribute('id',' ');
context.childNodes[i].setAttribute('id','activated');
box.childNodes[page].setAttribute('id',' ');
box.childNodes[i].setAttribute('id','act');
page = i
}
</script>
</head>
<body>
<!-- HTML頁面布局 -->
<ul class="box">
<li class="tit1" id="act" onclick="change(1)">房產(chǎn)</li>
<li class="tit2" onclick="change(3)">家居</li>
<li class="tit3" onclick="change(5)">二手房</li>
</ul>
<div class="context">
<ul id="activated">
<li>275萬購昌平鄰鐵三居 總價20萬買一居</li>
<li>200萬內(nèi)購五環(huán)三居 140萬安家東三環(huán)</li>
<li>北京首現(xiàn)零首付樓盤 53萬購東5環(huán)50平</li>
<li>京樓盤直降5000 中信府 公園樓王現(xiàn)房</li>
</ul>
<ul >
<li>40平出租屋大改造 美少女的混搭小窩</li>
<li>經(jīng)典清新簡歐愛家 90平老房煥發(fā)新生</li>
<li>新中式的酷色溫情 66平撞色活潑家居</li>
<li>瓷磚就像選好老婆 衛(wèi)生間煙道的設(shè)計</li>
</ul>
<ul >
<li>通州豪華3居260萬 二環(huán)稀缺2居250w甩</li>
<li>西3環(huán)通透2居290萬 130萬2居限量搶購</li>
<li>黃城根小學(xué)學(xué)區(qū)僅260萬 121平70萬拋!</li>
<li>獨家別墅280萬 蘇州橋2居優(yōu)惠價248萬</li>
</ul>
</div>
</body>
</html>
我是這么寫的…感覺我寫的好多沒用的…