谷歌浏览器 > 控制台.info > 打印文字为黑色(与console.log相同)

7

有人遇到这种情况吗,你执行以下代码:

console.info ('hi');

结果打印出来的 "hi" 是黑色的,而不是以前一直是蓝色的。如下图所示:

https://postimg.org/image/g8isebbrn/

多年来,console.info 一直用于以蓝色输出信息!现在,让我惊讶的是,已经不再是这样了。

我在 Chrome 浏览器中找不到任何设置可以使输出变成这个颜色盲!


Chrome开发人员决定你不需要它 https://crbug.com/712103 - wOxxOm
让人无语。你知道有什么扩展程序可以恢复它的意义吗? - Average Joe
1个回答

3

看起来这是故意缩进的设计,想不到吧,但是...这里有一个替代方案!

console.log("%c这将用大号蓝色文字格式化", "color: blue; font-size: x-large");

不要忘记其中的%c

如果要将其包装在函数中,可以使用以下启动器代码:

function sysConsole(messageType,message){ 
    if ( messageType === 'info') {
      s = '%c' + '##' + messageType + ': ' + message; 
      // the ## will enable you to do filtering at the console 
      // by typing ##info 
      console.log (s, 'color: blue;'); 
    }

    // you can have other messageTypes later (to be wired for different colors )

    return false;
  }

如需未来的灵感,请访问https://developers.google.com/web/tools/chrome-devtools/console/console-write


1
console.info 被移除了吗?在这里提到了:https://developers.google.com/web/tools/chrome-devtools/console/console-reference#consoleinfoobject_object - swrobel

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接