js点击弹出提示层2秒钟之后自动消失

我找了很多代码,在百度上,但是都不好使,谁能帮帮忙,效果就是点击一个按钮后出来一个提示层,然后几秒钟之后自动消失了,谢谢啊,在线等啊,非常感谢~

这样:

 <script>

        jQuery(document).ready(function($) {

            $('.theme-login').click(function(){

                $('.theme-popover-mask').fadeIn(100);

                $('.theme-popover').slideDown(200);

                setTimeout(function() {

                    console.log('22222222222');                            

                    $('.theme-popover-mask').fadeOut(100);

                    $('.theme-popover').slideUp(200);            

                }, 1000);               

            })

            $('.theme-poptit .close').click(function(){

                $('.theme-popover-mask').fadeOut(100);

                $('.theme-popover').slideUp(200);

            })

        })

    </script>

扩展资料:

利用setTimeout(),setTimeout()方法用于在指定的毫秒数后调用函数或计算表达式

语法:

setTimeout(code,millisec)

提示和注释:

setTimeout() 只执行 code 一次。如果要多次调用,请使用 setInterval() 或者让 code 自身再次调用 setTimeout()。

温馨提示:内容为网友见解,仅供参考
第1个回答  推荐于2016-02-23
<button id="btn" onclick="func()">btn</button>
<script>
var layer=document.createElement("div");
layer.id="layer";
function func()
{
var style=
{
background:"#f00",
position:"absolute",
zIndex:10,
width:"200px",
height:"200px",
left:"200px",
top:"200px"
}
for(var i in style)
layer.style[i]=style[i];
if(document.getElementById("layer")==null)
{
document.body.appendChild(layer);
setTimeout("document.body.removeChild(layer)",2000)
}
}

</script>

追问

你好,非常感谢你的回答,但是,要是在这个弹出层里加 该怎么加呢?

追答

譬如加什么?加文字的话直接layer.innerHTML=xxx
如果加标签的话创建标签appendChild添加进去

追问

啊~ 文字加上了,呵呵,谢谢你,太感谢了,但是就js里写的这些样式如果不满足我想要写的,比如我想加border,padding之类的,该怎么办呢?

追答var style=
    {
        background:"#f00",
        position:"absolute",
        zIndex:10,
        width:"200px",
        height:"200px",
        left:"200px",
        top:"200px"
    }
    这个是样式表,在里面改或者添加

本回答被提问者和网友采纳
第2个回答  2013-09-06
百度搜jbox.保你满意
相似回答