前端 自定义弹出框-提示框(一)

js默认提示框

js有三种默认提示框

提示框 alert('hello world!');

自定义提示框

下文通过js自动生成一个自定义提示框

    function showDialog(content) {
        var layer = document.createElement("div");
        layer.id = "layer";
        var style = {
            background: "#ccc",
            position: "absolute",
            zIndex: 10,
            width: "auto",
            height: "40px",
            left: "50%",
            top: "0%",
            marginLeft: "-100px",
            marginTop: "10px",
            padding: "4px 10px"
        }
        for (var i in style) {
            layer.style[i] = style[i];
        }
        if (document.getElementById("layer") == null) {
            document.body.appendChild(layer);
            layer.innerHTML = content;
            layer.style.textAlign = "center";
            layer.style.lineHeight = "40px"; 
            setTimeout("document.body.removeChild(layer)", 3000)
        }
    }

效果如下:

 

posted @ 2020-03-19 00:25  唐宋元明清2188  阅读(236)  评论(0编辑  收藏