<html>
<head>
    <title></title>
    <script type="text/javascript">
        function sAlert(str) {
            var msgw, msgh, bordercolor;
            msgw = 300;//提示窗口的宽度
            msgh = 200; //提示窗口的高度
            titleheight = 25; //提示窗口标题宽度
            bordercolor = "#FF3C00"; //提示窗口的边框颜色
            titlecolor = "#D2CECE";//提示窗口的标题颜色
            var sWidth, sHeight;
            sWidth = document.body.clientWidth; //bod对象宽度
            if (window.innerHeight && window.scrollMaxY) {
                sHeight = window.innerHeight + window.scrollMaxY;
            }
            else if (document.body.scrollHeight > document.body.offsetHeight) {
                sHeight = document.body.scrollHeight;
            }
            else {
                sHeight = document.body.offsetHeight;
            } //以上得到整个屏幕的高
            var bgObj = document.createElement("div"); //创建一个div对象
            bgObj.setAttribute("id", "bgDiv");
            bgObj.style.position = "absolute"; //绝对定位
            bgObj.style.top = "0"; //顶部为0
            bgObj.style.backgroud = "#777"; //背景颜色
            bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishiOpacity=75)"; //ie浏览器透明度设置
            bgObj.style.opacity = "0.6"; //透明度(火狐中)
            bgObj.style.left = "0"; //左边为0
            bgObj.style.width = sWidth + "px";
            bgObj.style.height = sHeight + "px";
            bgObj.style.zIndex = "100"; //层的z轴位置
            document.body.appendChild(bgObj);

            var msgObj = document.createElement("div");
            msgObj.setAttribute("id", "msgDiv");
            msgObj.setAttribute("align","center");
            msgObj.style.position = "absolute";
            msgObj.style.top = "30%";
            msgObj.style.backgroud = "white";
            msgObj.style.border = "1px solid "+bordercolor;
            msgObj.style.left = "35%";
            msgObj.style.font = "12px/1.6en Verdana,Geneva,Arial,Helvetica,sans-serif";
            msgObj.style.width = msgw + "px";
            msgObj.style.height = msgh + "px";
            msgObj.style.textAlign = "center";//文本位置属性,居中
            msgObj.style.lineHeight = "25px"; //行间距
            msgObj.style.zIndex = "101"; //层的z轴位置


            var title = document.createElement("h4"); //创建一个h4对象
            title.setAttribute("id", "msgTitle"); //为h4对象添加标题
            title.setAttribute("align", "right"); //文字的对齐方式
            title.style.margin = "0"; //浮动
            title.style.padding = "3px"; //浮动
            title.style.backgroud = titlecolor; //背景颜色
            title.style.filter = "progid:DXImageTransform.Microsoft.Alpha(startX=20,startY=20,finishX=100,finishY=100,style=1,opacity=75,finishiOpacity=100);";
            title.style.opacity = "0.75"; //透明
            //title.style.border = "1px solid" + bordercolor;
            title.style.height = "25px"; //高度
            title.style.font = "12px Verdana,Geneva,Arial,Helvetica,sans-serif"; //字体属性
            title.style.color = "white"; //文字颜色
            title.style.cursor = "pointer";//鼠标样式
            title.innerHTML = "<a href=\"#\">关闭</a>";//显示的文字
            title.onclick = function () {
                document.body.removeChild(bgObj);//移除遮罩层
                document.getElementById("msgDiv").removeChild(title); //在提示框中移除标题
                document.body.removeChild(msgObj);//移除提示框
            }
            document.body.appendChild(msgObj); //在body中画出提示框层
            document.getElementById("msgDiv").appendChild(title); //在提示框中增加标题
            var txt = document.createElement("p");
            txt.style.margin = "0";//文本浮动
            txt.setAttribute("id", "msgTxt");//为p属性增加id属性
            txt.innerHTML = str;//把传进来的值赋给p属性
            document.getElementById("msgDiv").appendChild(txt); //把p属性增加到提示框中            
        }   
    </script>
</head>
<body>
<a href="#" onclick="sAlert('<a href=http://www.it300.net>测试效果</a>');">点击测试</a>
</body>
</html>

posted on 2011-09-20 11:18  易成波  阅读(579)  评论(0编辑  收藏  举报