<style>
.hide { display:none}
.show{ display:block}
</style>
<SCRIPT LANGUAGE=javascript>
<!--
function ShiftPic(obj)
{
if(obj.nextSibling.className=='hide'){ //doing sth.
}
}
function ShowHide(obj)
{
if(obj.lastChild.className=='hide')
{
obj.lastChild.className='show';
}
else
{
obj.lastChild.className='hide';
}
}
</SCRIPT><a href="#" onclick="ShowHide(this);return(false)"><img src="b.gif" alt="hide" onclick="ShiftPic(this)" /><span class="show">test</span></a>
.hide { display:none}
.show{ display:block}
</style>
<SCRIPT LANGUAGE=javascript>
<!--
function ShiftPic(obj)
{
if(obj.nextSibling.className=='hide'){ //doing sth.
}
}
function ShowHide(obj)
{
if(obj.lastChild.className=='hide')
{
obj.lastChild.className='show';
}
else
{
obj.lastChild.className='hide';
}
}
</SCRIPT><a href="#" onclick="ShowHide(this);return(false)"><img src="b.gif" alt="hide" onclick="ShiftPic(this)" /><span class="show">test</span></a>
将 html 看成一棵树.
<A> -- parent
/ <img> <span> -childs现在 ShowHide 方法里的参数 obj 是对象 <A>
从上面的图看, span 是不是 obj.lastChild ?
而
在 ShiftPic 方法里参数obj是对象 <img>
同样方法看, obj.nextSibling 不就是 span 了! 在这里你也可以
obj.parentElement.lastChild 这样获得 span 的.