導航:首頁 > 編程語言 > 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窗口居中相關的資料

熱點內容
編程小游戲是如何設計的 瀏覽:913
網路安全風險案例 瀏覽:46
司法考試哪個網站好 瀏覽:469
android搜索功能代碼 瀏覽:437
文件名如何沒有文字 瀏覽:601
吃雞地圖資源包文件路徑 瀏覽:267
cad文件轉移手機 瀏覽:733
指定區域網內文件delphi 瀏覽:638
蘋果5s充電介面維修 瀏覽:913
建行app怎麼老是信息填寫錯誤 瀏覽:832
羅技g903切換配置文件 瀏覽:649
游戲的數據在哪個英文文件夾 瀏覽:435
編程一般學什麼專業課 瀏覽:394
不屬於資料庫系統的主要組成部分 瀏覽:797
jdl是什麼網路詞 瀏覽:247
優酷的緩存視頻文件夾 瀏覽:842
jsp頁面獲取地址欄參數 瀏覽:893
怎麼帶小度app聽酷狗音樂的歌 瀏覽:17
icleanerpro白蘋果 瀏覽:786
2016年1024客戶端安卓 瀏覽:136

友情鏈接