带颜色的输出

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>带颜色的输出</title>
  </head>
  <body>
    <script>
      function consoleWithColor(str) {
        console.log(`%c${str}`, `color:rgb(${colorNum()},${colorNum()},${colorNum()})`);
      }
      function colorNum() {
        return String(Math.floor(256 * Math.random()));
      }
      consoleWithColor(undefined);
    </script>
  </body>
</html>

 

posted @ 2022-04-09 15:40  苹果π  阅读(13)  评论(0)    收藏  举报