js打印彩色菱形

2018-08-17 09:43:25来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>weirdo</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        .lx {
            text-align: center;
            letter-spacing: 5px;
            margin: 20px;
        }
    </style>
</head>
<body>
<div class="lx">
    <script>
        function cl() {
            var c = '0123456789abcdef';
            var cc = '#';
            cc += c.charAt(Math.round(Math.random() * (c.length - 1)));
            cc += c.charAt(Math.round(Math.random() * (c.length - 1)));
            cc += c.charAt(Math.round(Math.random() * (c.length - 1)));
            cc += c.charAt(Math.round(Math.random() * (c.length - 1)));
            cc += c.charAt(Math.round(Math.random() * (c.length - 1)));
            cc += c.charAt(Math.round(Math.random() * (c.length - 1)));
            return cc;
        }

        function ling(num) {
            for (var i = 1; i <= num; i += 2) {
                document.write('<p class="ling">');
                for (var j = 1; j <= i; j++) {
                    document.write('<span style="color:' + cl() + '">*</span>');
                }
                document.write('</p>');
            }
            for (var i = num; i >= 1; i -= 2) {
                document.write('<p class="ling">');
                for (var j = 1; j <= i; j++) {
                    document.write('<span style="color:' + cl() + '">*</span>');
                }
                document.write('</p>');
            }
        }

        ling(15);
    </script>
</div>
</body>
</html>

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:node:爬虫爬取网页图片

下一篇:js判断手机系统