百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>JS教程> js DIV延时几秒后消失或显示代码
分享文章到:

js DIV延时几秒后消失或显示代码

发布时间:01/15 来源: 浏览: 关键词:
小编来给大家介绍js DIV延时几秒后消失或显示代码,这里我我介绍了利用js原生态的写法,然后讲述了利用jquery的写法,有需要的朋友可参考。

1、最常用的方法:

 代码如下

<script language='javascript' type='text/javascript'>
$(function () {
    setTimeout(function () {
        $("divid").show();
    }, 6000);
})
</script>

2、第二种方法

jquery 让一个div延时消失,纯jQuery,不用settimeout,就用jQuery写。

 代码如下

 
<script language='javascript' type='text/javascript'>
$(document).ready(
    function()
    {
        /**
        *1.delay函数是jquery 1.4.2新增的函数
        *2.hide函数里必须放一个0,不然延时不起作用
        */
        $('#divid').delay(6000).hide(0);
    }
);
</script>

完整实例

 代码如下

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>div层延时消失</title>
<script>
function operate()
{
    document.getElementById('div_test').style.display="";
    setTimeout("disappeare()",2000);
}
function disappeare(){
    document.getElementById('div_test').style.display="none";
}
</script>
</head>

<body>
<input type="button" onclick="javascript:operate()" value="操作"/>
<div id="div_test" style="display:none;color:white;line-height:25px;position:absolute;z-index:100;left:50%;top:2%;margin-left:-75px;text-align:center;width:150px;height:25px;background-color:green;font-size:12px;">
    恭喜你,操作成功!
</div>
</body>
</html>

打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有5人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板