博主信息
博文 12
粉丝 1
评论 0
访问量 11048
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
Javascript基础--随机色的切换和倒计时的实现--五期线上培训--2019--03--28
文昌的博客
原创
787人浏览过

随机色的切换:

实例

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>随机色</title>
    <style>
        
    </style>
</head>

<body>
    <button onclick="bg_Color()">随机色</button>
    <script>
        function bg_Color(){
            var bg = "#"
            var r = Math.floor(Math.random()*10).toString()+Math.floor(Math.random()*10)
            var g = Math.floor(Math.random()*10).toString()+Math.floor(Math.random()*10)
            var b = Math.floor(Math.random()*10).toString()+Math.floor(Math.random()*10)
            bg+=r+g+b
            document.getElementsByTagName('body')[0].style.background = bg;
        }
    </script>
</body>

</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

倒计时的实现:

实例

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>倒计时</title>
    <style>
        p {
            height: 50px;
            width: 300px;
            margin: 100px auto;
        }

        span {
            display: inline-block;
            height: 50px;
            width: 50px;
            line-height: 50px;
            font-size: 50px;
            color: #f00;
            text-align: center;
        }
    </style>
</head>

<body>
    <p>
        还剩<span>5</span>秒跳转至
        <a href="http://www.php.cn">php中文网</a>
    </p>
    <script>
        var Espan = document.getElementsByTagName('span')[0];
        var i = 4;
        function fn() {

            if (i > 0) {
                Espan.innerHTML = i;
                i--;
            } else {
                window.location.href = "http://www.php.cn"
            }
        }
        setInterval("fn()", 1000);
    </script>
</body>

</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例


批改状态:未批改

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学