呵呵, 从MSDN里挖出来的源代码:function hideExamples()
{
var colPre=document.all.tags("PRE");
for (var i=0;i<colPre.length;i++)
{
if (colPre.item(i).className=="clsCode")
{
if (colPre.item(i).offsetHeight > 200)
{
var oSpan=document.createElement("P");
colPre.item(i).parentNode.insertBefore(oSpan,colPre.item(i));
oSpan.onclick=toggle;
oSpan.ShowHideType="Example"
oSpan.style.textDecorationUnderline=true;
oSpan.style.fontWeight="bold";
oSpan.style.cursor="hand";
// Code decoration (IE 5 only) will hide the example
if ( oBD.majorVer < 5 )
{
toggle(oSpan);
}
}
}
}
}
{
var colPre=document.all.tags("PRE");
for (var i=0;i<colPre.length;i++)
{
if (colPre.item(i).className=="clsCode")
{
if (colPre.item(i).offsetHeight > 200)
{
var oSpan=document.createElement("P");
colPre.item(i).parentNode.insertBefore(oSpan,colPre.item(i));
oSpan.onclick=toggle;
oSpan.ShowHideType="Example"
oSpan.style.textDecorationUnderline=true;
oSpan.style.fontWeight="bold";
oSpan.style.cursor="hand";
// Code decoration (IE 5 only) will hide the example
if ( oBD.majorVer < 5 )
{
toggle(oSpan);
}
}
}
}
}
.11{display:none;}
.22{display:visible;}
</style>
2. <div id=XX class=22>show the example</div>
3. <div id=YY class=11>hide the example</div>
4. <div id=ZZ class=11>代码的内容</div>
5. 在"show the example"上加事件处理程序,onclick="document.getElementById('XX').className=11;document.getElementById('YY').className=22";document.getElementById('ZZ').className=22"
6. 在"hide the example"上加,onclick="document.getElementById('XX').className=22;document.getElementById('YY').className=11";document.getElementById('ZZ').className=11"试试看.
你可能会有更好的方法!