第一种:弹出层、遮罩层、div层
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www./TR/1999/REC-html401-19991224/loose.dtd"> <HTML xmlns="http://www./1999/xhtml%22%3E%3CHEAD%3E%3CTITLE%3EJAVASCRIPT弹出DIV层窗口实例</TITLE> <META http-equiv=Content-Type content="text/html; charset=utf-8"> <style> #popupcontent{ position: absolute; visibility: hidden; overflow: hidden; border:1px solid #CCC; background-color:#F9F9F9; border:1px solid #333; padding:5px;}
</style> <script> var baseText = null; function showPopup(w,h){ var popUp = document.getElementById("popupcontent"); popUp.style.top = "200px"; popUp.style.left = "200px"; popUp.style.width = w + "px"; popUp.style.height = h + "px"; if (baseText == null) baseText = popUp.innerHTML; popUp.innerHTML = baseText + "<div id=\"statusbar\"><input type=\"button\" value=\"Close window\" onClick=\"hidePopup();\"></div>"; var sbar = document.getElementById("statusbar"); sbar.style.marginTop = (parseInt(h)-60) + "px"; popUp.style.visibility = "visible"; } function hidePopup(){ var popUp = document.getElementById("popupcontent"); popUp.style.visibility = "hidden"; } </script> <META content="MSHTML 6.00.2900.2838" name=GENERATOR></HEAD> <BODY> <div id="popupcontent">这是一个DIV弹窗效果!</div> <p><a href="#" onmouseover="showPopup(300,200);" >将鼠标移动到此</a><p> <p><a href="#" onclick="showPopup(300,200);" >点击这里查看弹出窗口</a></p> </BODY> </HTML>
第二种:弹出层、遮罩层、div层
<html> <head> <style> <!-- body{font-family:宋体; font-size:12px; padding:0px; margin:0px;} .showWindow:hover{color:#FF0000}
.win_bg{background:#CCC; opacity:0.2; filter:alpha(opacity=20); position:absolute; left:0px; top:0px; width:100%; height:100%; z-index:998;} .winTitle{background:#9DACBF; height:20px; line-height:20px} .winTitle .title_left{font-weight:bold; color:#FFF; padding-left:5px; float:left} .winTitle .title_right{float:right} .winTitle .title_right a{color:#000; text-decoration:none} .winTitle .title_right a:hover{text-decoration:underline; color:#FF0000} .winContent{padding:5px;} --> </style> <script language="javascript"> function showWindow(){ if(document.getElementById("divWin")) { $("divWin").style.zIndex=999; $("divWin").style.display=""; } else { var objWin=document.createElement("div"); objWin.id="divWin"; objWin.style.position="absolute"; objWin.style.width="520px"; objWin.style.height="220px"; objWin.style.border="2px solid #AEBBCA"; objWin.style.background="#FFF"; objWin.style.zIndex=999; document.body.appendChild(objWin); } if(document.getElementById("win_bg")) { $("win_bg").style.zIndex=998; $("win_bg").style.display=""; } else { var obj_bg=document.createElement("div"); obj_bg.id="win_bg"; obj_bg.className="win_bg"; document.body.appendChild(obj_bg); }
var str=""; str+='<div class="winTitle" onMouseDown="startMove(this,event)" onMouseUp="stopMove(this,event)"><span class="title_left">弹出式窗口</span><span class="title_right"><a href="javascript:closeWindow()" title="单击关闭此窗口">关闭</a></span><br style="clear:right"/></div>'; //标题栏 str+='<div class="winContent">这是一个页面内部弹出窗口,使用W3C的createElement()方法和appendChild()方法<br /> 用火狐打开可以拖动窗口(IE拖动可能有问题)</div>'; //窗口内容 $("divWin").innerHTML=str; } function closeWindow(){ $("divWin").style.display="none"; $("win_bg").style.display="none"; } function $(o){ return document.getElementById(o); } function startMove(o,e){ var wb; if(document.all && e.button==1) wb=true; else if(e.button==0) wb=true; if(wb) { var x_pos=parseInt(e.clientX-o.parentNode.offsetLeft); var y_pos=parseInt(e.clientY-o.parentNode.offsetTop); if(y_pos<=o.offsetHeight) { document.documentElement.onmousemove=function(mEvent) { var eEvent=(document.all)?event:mEvent; o.parentNode.style.left=eEvent.clientX-x_pos+"px"; o.parentNode.style.top=eEvent.clientY-y_pos+"px"; } } } } function stopMove(o,e){ document.documentElement.onmousemove=null; } </script> </head>
<body> <a class="showWindow" href="javascript:showWindow()">点击这里</a>打开窗口<br /> </body> </html>
第三种:弹出层、遮罩层、div层
自己下载个jquery.min.js
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title> New Document </title> <meta name="Generator" content="EditPlus"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> <script type="text/javaScript" src="jquery.min.js"></script> <script language="JavaScript"> function showWindow(){
mask=document.createElement("div"); var W=$(document).width(); var H=$(document).height(); mask.id="mask"; mask.style.cssText="position:absolute;z-index:5;width:"+W+"px;height:"+H+"px;background:#000;filter:alpha(opacity=30);opacity:0.3;top:0;left:0;"; document.body.appendChild(mask); var o = document.getElementById("edit"); o.style.display="block"; o.style.top="253px"; o.style.left="400px"; } </script> </head> <body> <a href="javascript:showWindow()">点击</a>
<div id="edit" style="display:none;position:absolute;z-index:100; border:solid 1px #79BCFF; background-color: #EEF2FB; width:400px;height:100px"> <form name="form1" id="form1" method="post" action="admin.php?ac=adgroup&op=edit" onsubmit=""> <table id="table1" width="400" cellpadding="0" cellspacing="0"> <tr bgcolor="#A0D0F5"> <span style="float:right;margin-top:5px;"><a onclick="closeWindow();" style="cursor: pointer;float:right;">[关闭]</a></span> <th colspan="2" style="font-size:14px;line-height:24px;">修改当前单元</th> </tr> <tr><td height="5"></td></tr> <tr> <td width="100" align="right">单元名称</td> <td width="300"><INPUT TYPE="text" NAME="adgroupName" id="adgroupID" onblur="checkKeyName(this)"><div></div></td> </tr> <!--<tr> <td align="right">出价</td> <td><INPUT TYPE="text" NAME="MaxPriceName" id='MaxPriceID' onblur="checkPrice(this)"><div></div></td> </tr>--> <tr><td> </td></tr> <tr> <td colspan="2"><input type="button" value="确认" onclick="up_adgroup()" style="margin-left:100px;"></td> </tr> </table>
</form> </div> </body> </html>
|