利用js对象弹出一个层

本文介绍了一种使用JavaScript创建自定义弹窗层的方法。通过定义一个名为cmsgbox的构造函数来设置弹窗的位置、大小及标题等属性,并演示了如何将其显示在网页上。该方法提供了一个简单的解决方案来实现网页上的弹出通知或对话框。

<!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>
 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值