javascript弹出提示框

先创建一个bodybg将整个页面覆盖,接着创建div将其绝对定位与页面

/**
 *
 * @param tip 显示的消息
 * @param flag 是否刷新  true or false
 */
function tipdialog(tip,flag){
        //获取页面高和宽
    var iWidth=document.documentElement.clientWidth;
    var iHeight=document.documentElement.clientHeight;
    var height=Math.max(document.body.clientHeight, iHeight);

    var top=(parseInt(height)-300)/2;
    var left=(parseInt(iWidth)-300)/2;
//创建覆盖页面的div
    var bodybg=document.createElement("div");
    bodybg.id="bodybg";
    bodybg.style.cssText = "position:absolute;left:0px;top:0px;width:"+iWidth+"px;height:"+
        Math.max(document.body.clientHeight, iHeight)
        +"px;filter:Alpha(Opacity=30);opacity:0.3;background-color:#000000;z-index:101;";
    document.body.appendChild(bodybg);

    bodybg.onclick=function(){

        if(flag){
            location.reload();
        }

//关闭 
   document.getElementById("dialogbg").style.display="none";

        //$("#dialogbg").fadeOut();
        document.body.removeChild(bodybg);
        document.body.removeChild(dialogbg);
    };
//创建弹出框div
    var dialogbg=document.createElement("div");
    dialogbg.id="dialogbg";
    dialogbg.style.cssText="width:300px;height:150px;position: absolute;overflow: hidden;z-index: 102;" +
        "background-color: white;color:red;border-radius:3px;box-shadow: 0px 0px 10px rgba(0,0,0,.35);display: none;";
    dialogbg.style.top=top+"px";
    dialogbg.style.left=left+"px";

    var titlebg=document.createElement("div");
    titlebg.style.cssText="width:300px;color:black;height: 30px;background-color: #93e0e6;text-align: center; line-height:30px;";
    titlebg.innerHTML="提示信息";

    var tipbg=document.createElement("div");
    tipbg.style.cssText="width: 300px;height: 120px;text-align: center;line-height: 120px;";

    tipbg.innerHTML=tip;

    document.body.appendChild(dialogbg);
    dialogbg.appendChild(titlebg);
    dialogbg.appendChild(tipbg);

//显示 

document.getElementById("dialogbg").style.display="block";

    //$("#dialogbg").fadeIn();

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值