如何在JavaScript中将Unicode字符记录到控制台? [英] How to log unicode characters to the console in JavaScript?

查看:54
本文介绍了如何在JavaScript中将Unicode字符记录到控制台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个匈牙利语声明,我想这样登录到控制台:

I have a hungarian statement that I would like to log to the console like this:

console.log('Probléma a működésben.');

但是它显示以下内容:


Probléma aműködésben。

Probléma a működésben.

非ASCII字符弄乱了,但是我不认为这是因为控制台不支持Unicode字符,因为如果我将日志直接粘贴到控制台中,则会产生正确的输出。

The non ASCII characters are messed up, but I don't think the reason for this is that the console doesn't support unicode characters, because if I paste the log straight into the console it produces the proper output.

我在Opera,Firefox,Chrome中对其进行了测试。在Win 8.1和OSX中也会发生,所以我们可以说这很普遍。

I tested it in Opera, Firefox, Chrome. Happens in Win 8.1 and OSX too, so we can say this is general.

对于正确的unicode控制台日志记录,还有其他应保留的东西,例如HTML字符集或文件

Are there other things that should persist for the proper unicode console logging, like HTML charset or file encode?

推荐答案

我发现,如果您在< meta> 标记在< head> 中将起作用:

I found out that if you set the proper charset in a <meta> tag in the <head> it will work:

<meta charset="UTF-8">

这篇关于如何在JavaScript中将Unicode字符记录到控制台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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