六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 216|回复: 0

js实现弹出层

[复制链接]

升级  56.67%

37

主题

37

主题

37

主题

秀才

Rank: 2

积分
135
 楼主| 发表于 2013-2-8 00:50:08 | 显示全部楼层 |阅读模式
下面是一个JavaScript代码实现的弹出层效果
 
<html>    <head>      <style type="text/css">        #tranDiv {           position:absolute;           left:0px;           top:0px;         }         #tranDivBack {           position:absolute;           left:0px;           top:0px;           width:100%;           height:100%;           background-color:#000000;           filter:alpha(Opacity=30);           -moz-opacity:0.3;           opacity:0.3;         }         #infoDiv {           position:absolute;           left:0px;           top:0px;           width:100%;           height:100%;           text-align:center;         }         .pop_box {           background:#FFF;           padding:10px;           border:#666 8px solid;         }       </style>      <script language="javascript">                function showWindow(width,height){            location.href="#";             var windowstr= document.getElementById("popLayer").innerHTML;           document.getElementById("infoDiv").innerHTML=windowstr;            document.getElementById("infoDiv").style.left=((document.body.clientWidth-width)>0?(document.body.clientWidth-width):0)/2+"px";            document.getElementById("infoDiv").style.top=100+"px";            document.getElementById("infoDiv").style.zIndex=10001;           document.getElementById("infoDiv").style.width=width+"px";            document.getElementById("infoDiv").style.height=height+"px";            document.getElementById("tranDiv").style.height=document.body.clientHeight+ "px";            document.getElementById("tranDiv").style.width=document.body.clientWidth+ "px";            document.getElementById("tranDiv").style.display="";            document.getElementById("tranDivBack").style.display="";            document.getElementById("tranDivBack").style.zIndex=10000;           document.getElementById("infoDiv").style.display="";          }          function closeWindow(){           document.getElementById("tranDiv").style.display="none";          }   function changeVal() {var time = document.getElementById("time");time.value = "";//alert(document.getElementById("link").innerHTML);   }   function getVal() {    var time = document.getElementById("time").value;var patrn = /[0-9]/;if(!patrn.exec(time)) {alert("内容只能为整数,请重新输入!");return false;}if(time <= 0) {alert("设置时间应该大于0,请重新输入!");return false;}document.getElementById("link").innerHTML = time;//alert(document.getElementById("link").innerHTML);document.getElementById("timeVal").value = document.getElementById("link").innerHTML;alert(document.getElementById("timeVal").value);closeWindow();   }    </script>    </head>      <div id="tranDiv" style="display:none;">      <div id="tranDivBack"></div>      <div id="infoDiv"></div>    </div>       <div id="popLayer" style="display:none;">      <div class="pop_box">  时间:<input type="text" value="小时(整数)" id="time" name="time"  /><br/><input type="button" value="确定" /><input type="button" value="关闭"  />    </div>    </div>    测试程序:<a id="link" href="javascript:showWindow(250,60);">时间</a> <input type="hidden" id="timeVal" value="0" />    </html>   注:document.getElementById("infoDiv").style.width在Firefox中必须为下面样式:
 
document.getElementById("infoDiv").style.width="180px" 
必须加双引号
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表