导航:首页 > 编程语言 > 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窗口居中相关的资料

热点内容
微信扫描下载苹果app 浏览:29
70炼金术升级 浏览:862
C文件检验 浏览:101
IccID未知是有网络锁吗 浏览:101
苹果5s怎么定位苹果6手机 浏览:556
苹果手机港版怎么解锁 浏览:189
根据xml规则读取excel文件 浏览:28
网络删除文件 浏览:325
苹果怎么共享wifi网络打印机 浏览:368
怎么用键盘拷贝u盘文件 浏览:664
js炫酷特效 浏览:69
什么样的app最有市场 浏览:563
腾讯地图如何截图工具 浏览:69
数据处理主要方法有哪些 浏览:567
ps6拖文件无法打开 浏览:668
有哪些比较好的书评app 浏览:520
java中char表示范围 浏览:154
python编程操作题如何批改 浏览:1
网络是什么原理图 浏览:670
apk音乐提取工具 浏览:89

友情链接