Re: [問題] ie6 childNodes.length
看板Web_Design作者azureblue520 (夢遊中........)時間15年前 (2010/04/08 22:02)推噓0(0推 0噓 1→)留言1則, 1人參與討論串3/3 (看更多)
※ 引述《TonyQ (沉默是金。)》之銘言:
:
: : ul = documetn.getElementByID("test")
: ^^^^ ^
: 要稍微注意繕誤喔:3
: : 在ie6 ul.childNodes.length 一直都只有2
: : 似乎讀不到第二層li
: : ie8、Firefox都可正常讀到長度
: 我剛用ie8測了一下也是取到 2,
: 這大概是各家解讀這個見解的不同 .
: (不過個人是覺得,取到2是比較正確的 , childNodes 應該只取下一層的元素.)
: : 請問這要怎麼解決呢?
: : 謝謝~~
: 如果說你只想取得 test 底下 所有li的數量 ,
: 對 test 下 getElementsByTagName("li") 也不失為一解.
: http://tonyq.org/test/testChildNode.html
測試到昏頭 文章打錯都沒發現 我程式中的是document.getElementId 感謝指正.
我主要的目的是要作動態選單 下列是javascript
function startList()
{
if (document.all&&document.getElementById)
{
navRoot = document.getElementById("nav");
for (i=0; i<navRoot.childNodes.length; i++)
{
node = navRoot.childNodes[i];
if (node.nodeName=="LI")
{
node.onmouseover=function()
{
this.className+=" over";
}
node.onmouseout=function()
{
this.className=this.className.replace(" over", "");
}
}
}
}
}
下面是css
div.sdmenu ul li
{
position: relative;
}
div.sdmenu ul
{
margin: 0;
padding: 0;
list-style: none;
width: 130px;
}
div.sdmenu li ul
{
position: absolute;
left: 129px;
top: 0;
display: none;
}
div.sdmenu ul li a
{
padding: 5px 5px;
background: #eee;
display: block;
color: #066;
text-align: center;
border-bottom: 1px solid #898585;
border-left: 1px solid #898585;
border-right: 1px solid #898585;
}
div.sdmenu li:hover ul
{
display: block;
}
在我原文ul的上一層還有包一個div class='sdmenu'
javascript比較少研究 對有些參數還不太熟悉
我測試ie8, chrome, firefox都是可以正常執行選單
即第二層會先隱藏
等滑鼠滑過才會顯示
只有ie6才會無法正常執行
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.229.66.229
→
04/08 22:03, , 1F
04/08 22:03, 1F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):