一个简单的html点击展开/关闭代码
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>hackhp blog</title> <style type="text/css"> #box,#box2,#box3,#box4{padding:10px;border:1px solid green;} </style> <script type="text/javascript"> function openShutManager(oSourceObj,oTargetObj,shutAble,oOpenTip,oShutTip){ var sourceObj = typeof oSourceObj == "string" ? document.getElementById(oSourceObj) : oSourceObj; var targetObj = typeof oTargetObj == "string" ? document.getElementById(oTargetObj) : oTargetObj; var openTip = oOpenTip || ""; var shutTip = oShutTip || ""; if(targetObj.style.display!="none"){ if(shutAble) return; targetObj.style.display="none"; if(openTip && shutTip){ sourceObj.innerHTML = shutTip; } } else { targetObj.style.display="block"; if(openTip && shutTip){ sourceObj.innerHTML = openTip; } } } </script> </head> <body> <!--链接式--> <p><a href="" onclick="openShutManager(this,'box3',false,'点击关闭','点击展开')">点击展开</a></p> <p id="box3" style="display:none">hackhp blog</p> <!--按钮式--> <p><button onclick="openShutManager(this,'box4',false,'点击关闭','点击展开')">点击展开</button></p> <p id="box4" style="display:none">hackhp blog</p> </body> </html>