将Unicode字符插入到JavaScript中 [英] Insert Unicode character into JavaScript

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

问题描述

我需要在我的html页面上插入一个欧米茄(Ω)。我使用它的HTML转义代码来做到这一点,所以我可以写Ω 并获得Ω。当我把它放入一个HTML元素时,这一切都很好;然而,当我尝试将它放入我的JS中时,例如 var Omega =Ω ,它将该代码解析为JS,整个事情都不起作用。任何人都知道如何去做这件事?

I need to insert an Omega (Ω) onto my html page. I am using its HTML escaped code to do that, so I can write Ω and get Ω. That's all fine and well when I put it into a HTML element; however, when I try to put it into my JS, e.g. var Omega = Ω, it parses that code as JS and the whole thing doesn't work. Anyone know how to go about this?

推荐答案

我猜你实际上想要 Omega 是一个包含大写的欧米茄的字符串吗?在这种情况下,你可以这样写:

I'm guessing that you actually want Omega to be a string containing an uppercase omega? In that case, you can write:

var Omega = '\u03A9';

(因为ω codepoint为U + 03A9的Unicode字符;即 03A9 937 ,除非写成四个十六进制数字。)

(Because Ω is the Unicode character with codepoint U+03A9; that is, 03A9 is 937, except written as four hexadecimal digits.)

这篇关于将Unicode字符插入到JavaScript中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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