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

热点内容
一台电脑如何共享文件夹 浏览:942
wps如何保存pdf文件 浏览:602
PS源文件是厘米 浏览:766
创建桌面文件夹路径 浏览:900
华为手机app应用数据哪些删除 浏览:765
数据库有哪些表格 浏览:741
bada12微信java 浏览:16
小白编程什么最好学 浏览:205
qq回头看头像 浏览:338
苹果换屏要多长时间 浏览:283
如何用平板电脑学编程 浏览:424
格式工厂怎么转换swf文件 浏览:817
怎么做一个试用网站 浏览:953
哪里有信息不对称的app 浏览:59
win10的gpeditmsc文件 浏览:451
4399游戏盒20版本 浏览:349
有什么找工作比较靠谱的app吗 浏览:921
如何给网站挂黑链 浏览:282
360断网急救箱网络异常修复不了 浏览:889
身份证验证的js文件 浏览:994

友情链接