第一種:彈出層、遮罩層、div層
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "<HTML xmlns="http://www.w3.org/1999/xhtml%22%3E%3CHEAD%3E%3CTITLE%3EJAVASCRIPT彈出DIV層窗口實(shí)例</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">這是一個(gè)DIV彈窗效果!</div>
<p><a href="#" onmouseover="showPopup(300,200);" >將鼠標(biāo)移動(dòng)到此</a><p>
<p><a href="#" onclick="showPopup(300,200);" >點(diǎn)擊這里查看彈出窗口</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="單擊關(guān)閉此窗口">關(guān)閉</a></span><br style="clear:right"/></div>'; //標(biāo)題欄
str+='<div class="winContent">這是一個(gè)頁面內(nèi)部彈出窗口,使用W3C的createElement()方法和appendChild()方法<br /> 用火狐打開可以拖動(dòng)窗口(IE拖動(dòng)可能有問題)</div>'; //窗口內(nèi)容
$("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()">點(diǎn)擊這里</a>打開窗口<br />
</body>
</html>
第三種:彈出層、遮罩層、div層
自己下載個(gè)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()">點(diǎn)擊</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;">[關(guān)閉]</a></span>
<th colspan="2" style="font-size:14px;line-height:24px;">修改當(dāng)前單元</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">出價(jià)</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="確認(rèn)" onclick="up_adgroup()" style="margin-left:100px;"></td>
</tr>
</table>
</form>
</div>
</body>
</html>
聯(lián)系客服