亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

關于index問題。求指教

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>我的選項卡</title>

<style type="text/css">

*{margin:0;padding:0;}

#box

{

width:275px;

height:220px;

margin:22px auto;

font-family:"微軟雅黑";

font-size:15px;

overflow:hidden;

}


ul

{

border-bottom:2px solid red;

height:30px;

}


li

{

list-style-type:none;

? ? float:left;

width:80px;

line-height:30px;

border-top:2px solid #999;

border-left:1px solid #999;

border-right:1px solid #999;

text-align:center;

margin-left:6px;


}


a

{

text-decoration:none;

color:#000;

display:block;

line-height:30px;

text-align:center;

? ??

}

.show

{

clear:both;

border-left:1px solid #999;

border-right:1px solid #999;

border-bottom:1px solid #999;

background: #FFC ;

}?


.active

{

background: #ffc;

border-top:2px solid red;

}


.hide

{

display:none;

}

</style>

<script type="text/javascript">

window.onload=function(){

var Head=document.getElementById("head");

? ?var Lists=Head.getElementsByTagName("li") ;

? ?var Box=document.getElementById("box");?

? ?var oDiv=Box.getElementsByTagName("div") ;?

? ?

? ?for(var i=0;i<Lists.length;i++)

? ?{

? Lists[i].index = i;/*這一句和后面? oDiv[this.index].className = "show"; 有什么關系?為什我去掉Lists[i].index = i這一句話,oDiv[this.index].className = "show";這句話就失效了??*/

? Lists[i].onmouseover=function()

? {

?for(var i=0;i<Lists.length;i++)

?{

Lists[i].className=""; ?

?}

?this.className="active";

?

?

?for(var j=0;j<oDiv.length;j++)

?{

?oDiv[j].className="hide";?

?}

? ? ? ? ? oDiv[this.index].className = "show";?

? } ?

? ?}

? ?

}

</script>

</head>


<body>

<div id="box">

? ? <ul id="head">

? ? ? ? <li ?class="active">房產</li>

? ? ? ? <li>家居</li>

? ? ? ? <li>二手房</li>

? ? </ul> ? ?

? ? ?<div class="show">

? ? ? ? <a href="#">275萬購昌平鄰鐵三居 總價20萬買一居</a>

? ? ? ? <a href="#">200萬內購五環三居 140萬安家東三環</a>

? ? ? ? <a href="#">北京首現零首付樓盤 53萬購東5環50平</a>

? ? ? ? <a href="#">京樓盤直降00 50中信府 公園樓王現房</a>

? ? ?</div>

??

? ? ?<div class="hide">

? ? ? ? <a href="#">京樓盤直降5000 中信府 公園樓王現房</a>

? ? ? ? <a href="#">200萬內購五環三居 140萬安家東三環</a>

? ? ? ? <a href="#">北京首現零首付樓盤 53萬購東5環50平</a>

? ? ? ? <a href="#">275萬購昌平鄰鐵三居 總價2一居0萬買</a>?

? ? ?</div>?

??

? ? ?<div class="hide">

? ? ? ? <a href="#">北京首現零首付樓盤 53萬購東5環50平</a>

? ? ? ? <a href="#">200萬內購五環三居 140萬安家東三環</a>

? ? ? ? <a href="#">275萬購昌平鄰鐵三居 總價20萬買一居</a>

? ? ? ? <a href="#">京樓盤直降5000 中信府 公園樓王現房</a>

? ? ?</div> ??

? ?

</div>


</body>

</html>


正在回答

1 回答

建議看看這個,閉包的原因:http://www.cnblogs.com/songjum/p/4545800.html

注意運用閉包的常見錯誤-->for(var i,len=xx.length;i<len;i++)循環;當我們所引用的自由變量為i時,由于i一直在內存中沒有釋放,所以函數每次alert(i)時,其值均為最終的i;

0 回復 有任何疑惑可以回復我~
#1

不是本人__

你如果去掉Lists[i].index = i,那么Lists便沒賦予index這個屬性,,所以沒用。
2016-05-12 回復 有任何疑惑可以回復我~
#2

慧女神 提問者

非常感謝!
2016-05-14 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

關于index問題。求指教

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號