首頁 > web前端 > js教程 > 主體

js實作列印一個彩色的菱形(程式碼)

不言
發布: 2018-08-16 10:51:42
原創
1973 人瀏覽過

這篇文章帶給大家的內容是關於js實作印一個彩色的菱形(程式碼),有一定的參考價值,有需要的朋友可以參考一下,希望對你有幫助。

<!DOCTYPE html>
<html>
<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>
    <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(&#39;<p>');
                for (var j = 1; j <= i; j++) {
                    document.write(&#39;<span style="color:&#39; + cl() + &#39;">*</span>');
                }
                document.write('</p>');
            }
            for (var i = num; i >= 1; i -= 2) {
                document.write('<p>');
                for (var j = 1; j <= i; j++) {
                    document.write(&#39;<span style="color:&#39; + cl() + &#39;">*</span>');
                }
                document.write('</p>');
            }
        }

        ling(15);
    </script>
</div>
</body>
</html>
登入後複製

相關推薦: 

#js如何實作圖片延遲載入? js實作圖片延遲載入的方法代碼

js時間相互轉換:時間戳轉為時間字串(程式碼)

##js中驗證數字的方法總結

以上是js實作列印一個彩色的菱形(程式碼)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!