導航:首頁 > 編程語言 > js怎麼彈出div窗口居中

js怎麼彈出div窗口居中

發布時間:2024-08-09 03:44:01

① 怎樣用js實現彈出窗口的居中

怎樣用js實現彈出窗口的居中
<script type="text/javascript">

function openwindow(url,name,iWidth,iHeight)
{
var url; //轉向網頁的地址;
var name; //網頁名稱,可為空;
var iWidth; //彈出窗口的寬度;
var iHeight; //彈出窗口的高度;
//window.screen.height獲得屏幕的高,window.screen.width獲得屏幕的寬
var iTop = (window.screen.height-30-iHeight)/2; //獲得窗口的垂直位置;
var iLeft = (window.screen.width-10-iWidth)/2; //獲得窗口的水平位置;
window.open(url,name,'height='+iHeight+',,innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no');
}

</script>

② 如何讓JS彈出的窗口居中

<script type="text/javascript">

function openwindow(url,name,iWidth,iHeight)
{
var url; //轉向網頁的地址;
var name; //網頁名稱,可為空;
var iWidth; //彈出窗口的寬度;
var iHeight; //彈出窗口的高度;
//window.screen.height獲得屏幕的高,window.screen.width獲得屏幕的寬
var iTop = (window.screen.height-30-iHeight)/2; //獲得窗口的垂直位置;
var iLeft = (window.screen.width-10-iWidth)/2; //獲得窗口的水平位置;
window.open(url,name,'height='+iHeight+',,innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no');
}

</script>

③ 如何讓JS代碼效果居中

普通居中方法:margin:0 auto;就可以實現。應該是樣頁面的一個DOM居中吧!就用相對定位就可以了。

下面是個小例子:

<body>
<divid="div"style="width:100px;height:100px;background:#ccc;display:none;"></div>
<inputtype="button"value="clickme"id="btn"/>
</body>
<script>
varoBtn=document.getElementById('btn');
varoDiv=document.getElementById('div');
oBtn.onclick=function(){
oDiv.style.cssText='width:100px;height:100px;background:#ccc;top:50%;left:50%;position:absolute;margin-left:-50px;margin-top:-50px;display:block;';
};
</script>
cssText需要將原樣式清空後再補填樣式。
主要是用樣式的定位來做。你可以通過頁面的寬度和高度去計算。

④ js使用div內容居中

1、准備好一個空的html結構的文檔。

⑤ 一段js代碼,請問使用什麼代碼可以讓其居中顯示出來

<html>
<body>
<div id="aa" align="center"></div>
<div id="bb" align="center"></div>
</body>
</html>
<script>
var a = "<h1>插入html代碼</h1>";
var b = "<h1>插入原始代碼</h1>";
document.getElementById("aa").innerHTML = a;
document.getElementById("bb").innerText = b;
</script>

代碼已貼上,自己回去試
其實方式有很多版種,這只是其中一種
我沒看明權白你的問題,所以把兩種插入js代碼的方式都寫出來了
.innerHTML 轉譯html代碼
.innerText 源碼什麼樣插入的時候就是什麼樣

⑥ 通過JS彈出的浮動DIV層,居中於窗口中。

把style裡面的left和top拿到js裡面寫
在CSS裡面用expression是只有IE支持的 這就是不兼容的東西
<div id="divCenter" align="center" style="position: absolute; z-index: 3; display: none; background-color: #fff;" >
<span style="background-color:Gray; width:390px; height:220px; text-align:center;"><BR /><BR />面板中的內容</span>
</div>
<script language="JavaScript">
document.getElementById('divCenter').style.left = (document.body.offsetWidth - 540) / 2;
document.getElementById('divCenter').style.top = (document.body.offsetHeight - 170) / 2 + document.body.scrollTop;
</script>
<a onclick="javascript:document.all.divCenter.style.display='block';">顯示該層</a>

閱讀全文

與js怎麼彈出div窗口居中相關的資料

熱點內容
三星電視拆機教程 瀏覽:19
創維怎麼連接網路 瀏覽:868
2007版word繪圖在哪裡 瀏覽:311
可以拍車牌的app是什麼 瀏覽:508
文件加個井字型大小什麼意思 瀏覽:155
怎麼刪除多重網路 瀏覽:999
求生之路2區域網聯機工具 瀏覽:827
說明文件結尾用什麼詞 瀏覽:578
發送的文件名變數字 瀏覽:778
檔案資料庫管理 瀏覽:992
微信acl是金融傳銷嗎 瀏覽:620
企業如何通過進行網路營銷 瀏覽:551
微信json轉換錯誤 瀏覽:364
拉勾勾是什麼網站 瀏覽:556
長沙哪個學校有大數據技術與應用 瀏覽:137
qq語音停止運行 瀏覽:312
java獲取系統當前時間並轉為秒 瀏覽:679
linux目錄文件數 瀏覽:994
ug如何用宏編程 瀏覽:857
在編程中P代表什麼 瀏覽:420

友情鏈接