当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 利用js对象弹出一个层

Javascript
javascript比较文档位置
关于document.cookie的使用javascript
js让一行页脚保持在底部
多浏览器兼容的右下角广告代码(已测)
javascript onkeydown实现键盘快捷键控制页面
javascript的键盘控制事件说明
不懂JavaScript应该怎样学
用javascript实现截取字符串包含中文处理的函数
摘自启点的main.js
js tab效果代码增强版
慢慢展开再慢慢收起的javascript广告效果
javascript String 对象
JS查看对象功能代码
javascript点击才出现验证码
js实现双击单元格变成文本输入框效果代码
js通用滑动门类
js动画效果打开层 关闭层
js插入字符到textarea的效果代码
javascript 获取网页标题
js调用flash的效果代码

Javascript 中的 利用js对象弹出一个层


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 114 ::
收藏到网摘: n/a

用js实现弹出层效果,一般用于代替alert

复制代码 代码如下:

<!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=gb2312" />
<title>软晨学习网-弹出一个层</title>
<script language="javascript">
function cmsgbox(vtitle,vwidth,vhight,vtop,vleft)
{
this.title=vtitle;
this.width=vwidth;
this.height=vhight;
this.top=vtop;
this.left=vleft;
this.id=0;
}
cmsgbox.prototype.showdiv=function()
{
var str="";
str+="<div id='div1' style='z-index:1;background-color:white;position:absolute;border:2px solid slategray;left:"+this.vleft+"px;top:"+this.vtop+"px;width:"+this.width+"px;'>";
str+="<div style='padding-bottom:2px;background-color:slategray;width:100%;height:16px;color:white;' >";
str+=" <div style='float:left;height:16px;overflow:hidden;margin:0px;padding:4px 0px 0px 5px;width:"+(parseInt(this.width)-24*2-5)+"px;'>"+this.title+"</div>";
str+=" <span style='width:14px;font-family:webdings;cursor:hand;'>0</span>";
str+=" <span style='width:14px;font-family:webdings;cursor:hand;' onclick='cmsgbox.closediv(this);'>r</span>";
str+="</div>";
str+="<div style=' margin:10px 5px 10px 10px;word-break:break-all;'>";
str+="xxx";
str+="</div>";
str+="</div>";
//document.write(str);
document.body.insertAdjacentHTML("beforeEnd",str);
}
/////////////////////窗口显示//////////////////////////////
function show()
{
var box=new cmsgbox('小家伙呀',400,300);
box.showdiv();
}
</script>
</head>
<style>
body{
font-size:12px;
}
</style>
<body>
<p onclick="show();">弹了一个层</p>
</body>
</html>