这是一段使用js来控制页面元素的隐藏与显示的代码。
在firefox与ie7里面测试通过。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>js控制元素的隐藏于现实,兼容firefox ie</title> <script> function toggle(el){ if(typeof(el)=="string"){el=document.getElementById(el);} if(el.style.display!=""){el.style.display="";return} if(el.style.display!="none"){el.style.display="none";return} } </script> </head> <body> <button onclick="toggle('name')">button1</button> <hr /> <input type=text name=xm id="name" /> <hr /> <button onclick="toggle('2')">button2</button> <hr /> <input type=text name=xx id="2" /> </body> </html>
提示:你可以先修改部分代码再运行。
Slloser 上海,浦东。 热衷于: 交互设计、网站产品 还有阳明心学 >>更详细