页面 弹出div 怎么写

accomp 2010-03-01 11:53:17
页面上有一个button 一个div
当点击button时,div在页面当中显示 ,需要具体代码 。谢谢 。
...全文
158 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
itliyi 2010-03-01
  • 打赏
  • 举报
回复
引用 2 楼 jianshao810 的回复:
顶一楼的。。不过,这只是一个开始
just begining
licao88 2010-03-01
  • 打赏
  • 举报
回复
其实就是div的display 属性修改就行了
shan1119 2010-03-01
  • 打赏
  • 举报
回复

<script type="text/javascript">
window.onload=function(){
var obj=document.getElementById("div1");
div1.style.position = "absolute";
div1.style.display = "none";
div1.style.width = "100";
div1.style.height = "100";
}
window.onresize=function(){
var obj=document.getElementById("div1");
div1.style.left = (document.body.clientWidth - parseInt(div1.style.width)) / 2 + "px";
div1.style.top = (document.body.clientHeight - parseInt(div1.style.height)) / 2 + "px";
}
function show(){
var obj=document.getElementById("div1");
div1.style.display = "";
div1.style.left = (document.body.clientWidth - parseInt(div1.style.width)) / 2 + "px";
div1.style.top = (document.body.clientHeight - parseInt(div1.style.height)) / 2 + "px";
div1.style.background = "#EEE";
div1.style.border = "1px solid #AAA";
}
</script>

<div id="div1"> </div>
<input type="button" value="show" onclick="show()">
jianshao810 2010-03-01
  • 打赏
  • 举报
回复
顶一楼的。。不过,这只是一个开始
2010-03-01
  • 打赏
  • 举报
回复

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
html, body{
font-size:12px; margin:0px; padding:0px;
}
</style>
<script type="text/javascript">
function show(){
var width = Math.max(document.body.clientWidth, document.documentElement.clientWidth);
var height = Math.max(document.body.clientHeight, document.documentElement.clientHeight);
var layer = document.getElementById("layer1");
layer.style.display = "block";
layer.style.left = (width - layer.offsetWidth) / 2 + "px";
layer.style.top = (height - layer.offsetHeight) / 2 + "px";
}
</script>
</head>

<body>
<div id="layer1" style="display:none;position:absolute; width:300px; height:200px; border:1px solid #ccc; background:#F8F8F8;">测试</div>
<input type="button" value="显示" onclick="show()" />
</body>
</html>

cloudgamer 2010-03-01
  • 打赏
  • 举报
回复

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧