console.log输出五彩斑斓的颜色

console.log 最经常使用它在控制台输出信息然后进行代码调试,会发现输出信息的颜色永远是黑色。本文教学如何用 console.log在控制台输出具有五彩斑斓颜色的信息。

单色输出

console.log('\x1B[31m红色\x1B[34m 蓝色')

 

console.log('%c字符:', 'color:red', type)

console.log('%c当前环境:' + type, 'color:blue')

多色输出

console.log('%c123%c456', 'color: blue', 'color: green')
console.log.apply(void 0, ['%c123%c456', 'color: blue', 'color: green'])

 

背景输出

console.log('\x1b[43m背景')

背景+颜色输出

console.log('%c hello world ',
      'background: black; color: red')

背景+颜色+样式输出

console.log('%c 输出 %c 大大 a %c 颜色', 'color:red;', 'font-size:30px;', 'color:blue;background:yellow;')

其他输出

warn输出:

console.warn('hello world')

error输出:

console.error('hello world')

body输出:

console.log('%o', document.body)

相关推荐

  1. 数据输入输出(C++)

    2024-04-12 16:30:02       59 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-12 16:30:02       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-12 16:30:02       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-12 16:30:02       87 阅读
  4. Python语言-面向对象

    2024-04-12 16:30:02       96 阅读

热门阅读

  1. AcWing-5:多重背包问题 II

    2024-04-12 16:30:02       37 阅读
  2. C++| QT定时器QTimer

    2024-04-12 16:30:02       34 阅读
  3. 探索JVM类加载机制

    2024-04-12 16:30:02       29 阅读
  4. SQL SERVER 备份

    2024-04-12 16:30:02       32 阅读
  5. stmmac_dvr_probe解析

    2024-04-12 16:30:02       39 阅读
  6. Go 之缓冲通道限制协程并发数目

    2024-04-12 16:30:02       34 阅读
  7. C语言什么是寄存器变量?如何实现?

    2024-04-12 16:30:02       39 阅读
  8. 36岁程序员,10年前错过了阿里,我一点都不后悔

    2024-04-12 16:30:02       38 阅读
  9. 【蓝桥杯日常】

    2024-04-12 16:30:02       36 阅读