是否有可能呈现HTML到Javascript控制台? [英] Is it possible to render HTML into Javascript console?

查看:162
本文介绍了是否有可能呈现HTML到Javascript控制台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(log / info / warn):

  console.html( < H1>你好!< / H1>中); 

会呈现...



您好!



...进入控制台面板。是否有可能?



ps .:为记录,我希望有比log / info / warn /错误消息更多的着色选项。

解决方案

以某种方式可以使用

示例:

I would like to render HTML from a console.(log/info/warn):

console.html("<h1>Hello!</h1>");

would render…

Hello!

…into the console panel. Is it possible somehow?

ps.: for the record, I would like to have more coloring options than log/info/warn/error messages.

解决方案

In a way it's possible using the CSS format specifier.

Example:

console.log("%cThis will be formatted with large, blue text", "color: blue; font-size: x-large");

The CSS format specifier allows you to customize the display in the console. Start the string with the specifier and give the style you wish to apply as the second parameter.

This feature is supported by all main browser developer tools. See the reference for the Chrome DevTools, the one for the Firefox DevTools or the one for Firebug.

So while you can't use HTML per se, you can style whatever text you want using CSS to mimic many HTML elements:

console.log("%cHello!", "font-size: 3em");

这篇关于是否有可能呈现HTML到Javascript控制台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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