javascript彈出一個層并增加一個覆蓋層
更新時間:2008年10月10日 23:14:41 作者:
彈出一個層的js代碼,比較不錯
復(fù)制代碼 代碼如下:
<!--內(nèi)容層-->
<div id="ShopConfirmLayer" style="position:absolute;top:300px;left:100px;z-index:900;border:1px red solid;width:500px;display:none;">
<input name="button1" value="關(guān)閉" type="button" onclick="CloseShopConfirm()"/>
</div>
<!--覆蓋層-->
<div id="webBgLayer" style="position:absolute;top:0px;left:0px;z-index:899;background-color:#ccc;height:100%;width:100%;display:none;-moz-opacity:0.5;filter:alpha(opacity=50);"></div>
<script type="text/javascript">
function ShopConfirm(str){
var ShopConfirmLayer=document.getElementById("ShopConfirmLayer");
var webBgLayer=document.getElementById("webBgLayer");
ShopConfirmLayer.innerHTML=str;
ShopConfirmLayer.style.display="";
ShopConfirmLayer.style.left=parseInt((document.documentElement.scrollWidth-ShopConfirmLayer.offsetWidth)/2)+document.documentElement.scrollLeft+"px";
ShopConfirmLayer.style.top=Math.abs(parseInt((document.documentElement.clientHeight-ShopConfirmLayer.offsetHeight)/2))+document.documentElement.scrollTop+"px";
webBgLayer.style.display="";
webBgLayer.style.height=document.documentElement.scrollHeight+"px";
}
function CloseShopConfirm(){
var ShopConfirmLayer=document.getElementById("ShopConfirmLayer");
var webBgLayer=document.getElementById("webBgLayer");
ShopConfirmLayer.style.display="none";
webBgLayer.style.display="none";
}
</script>
注意上面的代碼頭部DTD應(yīng)該是這樣:
復(fù)制代碼 代碼如下:
<!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">
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁面才能執(zhí)行]
相關(guān)文章
前端date.locale?is?not?a?function錯誤的簡單解決辦法
這篇文章主要給大家介紹了關(guān)于前端date.locale?is?not?a?function錯誤的簡單解決辦法,文中通過圖文介紹的非常詳細,需要的朋友可以參考下2023-09-09
javascript event在FF和IE的兼容傳參心得(絕對好用)
event在IE和FF不兼,下面為大家分享的是javascript event在FF和IE的兼容傳參心得,需要的朋友可以參考下2014-07-07
JS實現(xiàn)的一個簡單的Autocomplete自動完成例子
這篇文章主要介紹了JS實現(xiàn)的一個簡單的Autocomplete自動完成例子,需要的朋友可以參考下2014-04-04

