Change console.log message color

后端 未结 7 706
我寻月下人不归
我寻月下人不归 2021-01-31 03:12

Is there a way to do something like:

console.log(\"hello world\", \'#FF0000\')

in Chrome/Safari or Firefox ?

7条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-31 03:16

    This works:

    function colorTrace(msg, color) {
        console.log("%c" + msg, "color:" + color + ";font-weight:bold;");
    }
    colorTrace("Test Me", "red");
    

提交回复
热议问题