简体   繁体   English

外部JavaScript文件的Charset UTF-8

[英]Charset UTF-8 for external JavaScript file

I add an external JavaScript file like this: 我添加一个外部JavaScript文件,如下所示:

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <script charset="utf-8" type="text/javascript" src="js/panel.js" ></script>
</head>

But the text stored in panel.js file is displayed like this in the HTML file: 但是存储在panel.js文件中的文本在HTML文件中显示如下:

H69�*

When I put JavaScript code in the HTML page, the text is displayed properly. 当我将JavaScript代码放入HTML页面时,文本将正确显示。 But when I put JavaScript code in panel.js , it does not work. 但是,当我将JavaScript代码放入panel.js时 ,它不起作用。

Then the file maybe is not properly saved as UTF-8. 然后,该文件可能未正确保存为UTF-8。

$ file -i panel.js

What's the output? 输出是什么?

If you use, for example Vi, open the file and save it with: 如果使用例如Vi,请打开文件并使用以下命令保存:

:w ++enc=utf-8 %

在Mac OS中,它是大写字母-i ...像这样:

file -I

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM