Javascript中的国际字符 [英] international characters in Javascript

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

问题描述

我正在开发一个网络应用程序,在这里我用XML将数据从服务器传输到浏览器。

I am working on a web application, where I transfer data from the server to the browser in XML.

因为我是丹麦语,我很快遇到问题与æøå

Since I'm danish, I quickly run into problems with the characters æøå.

我知道在HTML中,我使用 ; amp; aelig;& amp; oslash;& amp; aring; for æøå

I know that in html, I use the "æøå" for æøå.

但是,一旦字符通过JavaScript,当使用æøå<时,我会得到 / code>和& aelig;& oslash;& aring;将按原样打印。

however, as soon as the chars pass through JavaScript, I get black boxes with "?" in them when using æøå, and "&aelig;&oslash;&aring;" is printed as is.

我已经确保将其设置为utf-8,但这不是很有帮助。

I've made sure to set it to utf-8, but that isn't helping much.

理想情况下,我想要它与任何工作特殊字符(自然)。

Ideally, I want it to work with any special characters (naturally).

不起作用的示例包括如下:

The example that isn't working is included below:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
        <script type="text/javascript" charset="utf-8">
            alert("&aelig;&oslash;&aring;");
            alert("æøå");

        </script>
    </head>
    <body>
    </body>
</html>

我做错了什么?

好的,由于Grapefrukts答案,我得到它的工作。

Ok, thanks to Grapefrukts answer, I got it working.

我实际上需要它来自MySQL服务器的数据。由于以UTF-8编码保存文件仅解决了静态内容的问题,我想我将包括来自MySQL服务器的字符串的解决方案,使用PHP拉出:

I actually needed it for data coming from an MySQL server. Since the saving of the files in UTF-8 encoding only solves the problem for static content, I figure I'd include the solution for strings from a MySQL server, pulled out using PHP:

utf8_encode($ MyStringHere)

推荐答案

-8在header是不够的。我想你没有将你的文件保存为UTF-8。任何合理高级的文本编辑器将有此选项。试试,我相信它会工作!

Just specifying UTF-8 in the header is not enough. I'd bet you haven't saved your file as UTF-8. Any reasonably advanced text editor will have this option. Try that and I'm sure it'll work!

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

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