JS关于获取兄弟节点的问题
各位前辈,情况是这样的:我想通过 onMouseOver="mcancelclosetime(m1)"来改变<a></a>的属性;两端代码如下
<li>
<a href="#" onMouseOver="mopen('m1')" onMouseOut="mclosetime()">校情总揽</a>
<div id="m1" onMouseOver="mcancelclosetime(m1)" onMouseOut="mclosetime()">
<a href="#">学校简介</a>
<a href="#">历史沿革</a>
<a href="#">现任领导</a>
<a href="#">历任领导</a>
<a href="#">文化标识</a>
<a href="#">学校导图</a>
<a href="#">校园风光</a>
<a href="#">数据江财</a>
</div>
</li>
function mcancelclosetime(child_id)
{
/*var child_to_father = document.getElementById('child_id');
var oa = child_to_father.parentNode.getElementsByTagName('a');
oa[0].style.background = color.yellow;
oa[0].style.color = color.black;*/
if(closetimer)
{
window.clearTimeout(closetimer);
closetimer = null;
}
}
按道理应该没错吧?
------解决方案-------------------- <div id="m1" onMouseOver="mcancelclosetime(
'm1')" onMouseOut="mclosetime()">
如果是使用nextSibling或者previousSibling属性,注意非IE浏览器下空白节点也算一个,自己注意判断nodeType
------解决方案--------------------<div id="m1" onMouseOver="mcancelclosetime(
'm1
')" onMouseOut="mclosetime()">
var child_to_father = document.getElementById(child_id);
var oa = child_to_father.parentNode.getElementsByTagName('a');
oa[0].style.background = color.yellow;
oa[0].style.color = color.black;