<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>oec2003</title> <script language="JavaScript" type="text/JavaScript"> <!-- function toggle(targetid){ if (document.getElementById){ target=document.getElementById(targetid); if (target.style.display=="block"){ target.style.display="none"; } else { target.style.display="block"; } } } --> </script> <style type="text/css"> <!-- #div1{ background-color:#000000; height:400px; width:400px; display:none; } --> </style> </head> <body> <input type="button" value="显示/隐藏" /> <center> <div></div></center> 居中的DIV </body> </html>
示例三:
先来看一个最简单的实例,这个可以实现显示和隐藏层
<div></div><input type="button" /> function $_(id){ return document.getElementById(id); }; function display(x){ $(x).style.display=($(x).style.display=="none")?"":"none"; };
下面是关闭层,其实原理 是一样的只是加了个效果。
<!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>无标题文档</title> <style type="text/css"> body{ position:relative;} .wang{ width:100%; height:100%; background:#CCC; display:none; z-index:10; position:fixed; top:0px; left:150px; margin:0 auto; left:inherit; padding:0;filter:alpha(opacity=60); /* 针对IE浏览器的透明度 */ opacity:0.6; /* 针对FF浏览器的透明度 */} .wang ul{ width:100px; height:100px; margin:0 auto;} </style> </head> <body> <a>弹出</a><input type="text" /> <div><ul><form><label>姓名</label><input type="text" /><br /><label>密码</label><button>关闭</button></form></ul></div> <script type="text/javascript"> function dianji(){ x=document.getElementById("xian"); x.style.display="block"; return false; } function guanbi(name){ var c=document.getElementById("wangyan").value; if(c==3){ x.style.display='none'; return false; } } </script> </body> </html>
您可能感兴趣的文章: