当前位置: 移动技术网 > IT编程>开发语言>JavaScript > JS打印彩色菱形的实例代码

JS打印彩色菱形的实例代码

2018年08月18日  | 移动技术网IT编程  | 我要评论

效果图如下所示:

具体代码如下所示:

<!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>

总结

以上所述是小编给大家介绍的js打印彩色菱形的实例代码,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网