在Chrome的控制台中显示控制字符?

时间:2012-10-09 04:17:05

标签: javascript google-chrome console

有没有办法迫使Chrome的JS控制台显示像Firefox这样的新行?

铬:

enter image description here

火狐:

enter image description here

某处可能是一个隐藏的开关?

4 个答案:

答案 0 :(得分:8)

您可以使用encodeURI来显示隐藏的内容。

像这样encodeURI("a\nb")而不是"a\nb"

Chrome EncodeURI

答案 1 :(得分:2)

在node.js中,require("util").inspect做了非常相似的事情。我无法找到等效的浏览器,但幸运的是node.js implementation非常直接:

JSON.stringify(value)
    .replace(/^"|"$/g, '')
    .replace(/'/g, "\\'")
    .replace(/\\"/g, '"')
;

在您的情况下,只需JSON.stringify(value)即可。

希望这有帮助。

答案 2 :(得分:0)

你可以试试这种方式

var x = 'a\\nb';

编辑:

您可以在字符串中使用十六进制字符。

\ = '\u005C'
> var x = 'a\u005Cnb';
> x
<- "a\nb"
> x === "a\nb" is false.
> x === "a\\nb" is true or x === 'a\u005Cnb' is true.

您可以查看链接。

http://mathiasbynens.be/notes/javascript-escapes http://code.cside.com/3rdpage/us/javaUnicode/converter.html

答案 3 :(得分:0)

您可以对值进行字符串化处理以获取这些不可见的字符:

> JSON.stringify("a\nb")
<- ""a\nb""
相关问题