控制台消息JavaScript与绿色复选标记 [英] console message JavaScript with green checkmark

查看:119
本文介绍了控制台消息JavaScript与绿色复选标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b $我想知道是否可能在控制台中出现绿色复选标记,就像console.warn有黄色警告标志,console.error有红色错误标志。 b

我在互联网上搜索过,如果已经有这样的功能,但我找不到它。现在我正在寻找一种在 console.log 消息之前放置图标的方法。



这可能吗? ?

解决方案

当然是。您可以在Chrome中使用CSS:

  console.log(%c hi,background:url(path / to / your / icon.png)0 0 no-repeat; padding-left:20px;); 

文档
$ b


开发工具支持以下格式
$ b %c根据您提供的CSS样式格式化输出字符串。

注意:



控制台出于某种奇怪的原因不支持后台重复。所以你最好在你的图标上添加一些填充,否则将图标移动到右侧:

  console.log(hi%c,background:url(path / to / your / icon.png)0 0 no-repeat; padding-left:20px;); 


I was wondering if the was a possibility to have a green checkmark in your console just like console.warn has the yellow warning sign and console.error has the red error sign.

I have searched on the internet if there already was a function like that, but I couldn't find it. Now I'm looking for a way to put an icon before a console.log message.

Is this possible?

解决方案

Certainly is. You can use CSS in Chrome:

console.log("%c hi", "background: url(path/to/your/icon.png) 0 0 no-repeat; padding-left: 20px;");

From the documentation:

Dev Tools supports the following format specifiers:

%c Formats the output string according to CSS styles you provide.

Caveat:

The console doesn't support background-repeat for some odd reason. So you'd be better either adding some padding to your icon, or else moving the icon to the right-hand side:

console.log("hi %c", "background: url(path/to/your/icon.png) 0 0 no-repeat; padding-left: 20px;");

这篇关于控制台消息JavaScript与绿色复选标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆