Javascript 被转换为汉字

标签 javascript html angularjs

我有这个使用 Angular 1.6.1 的简​​单 Angular 应用。

index.html

<!DOCTYPE html>
<html ng-app="App">

<head>
    <title>Test</title>

    <script src="bower_components/angular/angular.js"></script>
    <script src="app/app.js"></script>
</head>

<body>
    <div>
        <home></home>
    </div>
</body>
</html>

应用程序.js

(function() {

    'use strict';

    var app = angular.module('App', []);

    app.component('home', {
            template: '<h1>{{$ctrl.head}}</h1><ul><li>1</li><li>2</li></ul>',
            controller: function() {
                var vm = this;

                this.head = "ONE";
            }
        });
})();

这将在 IE11 中正常加载并正确显示,但无法在 Chrome(55.0.2883.87 beta(64 位)或 FF(51.0b13(32 位))上加载,我完全不知道为什么......

当我在 Chrom Dev Tool 的 Sources 选项卡中单击 app.js 时,源代码是奇怪的中文字符,但通过 Notepad++ 查看源代码,一切看起来都正常......?!?!

这是 chrome 上的 devconsole 截图

enter image description here

对于添加到 index.html 的每个 JS 文件,我都可以看到相同的问题。 我没有在我的 PC 的浏览器中更改任何区域设置或任何其他内容......

我不知道为什么会这样。有人见过这样的东西吗?

最佳答案

所有文件都是通过键入在命令行中创建的

echo "" >> app.js

这已将编码设置为 UCS-2 LE BOM,如 Notepad++ 中显示的那样,由于某些未知原因,Chrome 和 firefox 无法正确读取文件 ...

enter image description here

因此在 Notepad++ 中将文件转换为 UTF-8-BOM(菜单 -> 编码 -> 转换为 UTF-8-BOM)文件读取正常并且一切正常...

我仍然对为什么旧的 IE 能够正常读取网站,但更现代的浏览器却失败了......

关于Javascript 被转换为汉字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41638967/

相关文章:

javascript - 复制 Yelp 星级评论小部件

html - 将嵌套 DIV 对齐到父 DIV 的底部 - 响应式 - Bootstrap3

angularjs - Angular $http 获取 :id

javascript - Angular js : set option value after filling options in select

javascript - Angularjs 中 Controller 的文档查询选择器

javascript - 如果第一个回调没有返回 Promise,那么可以调用吗?

javascript - 重新打开时出现空 Fancybox v2 登录对话框

javascript - react .js : Defining custom attributes

html - 两个输入的单个标签

javascript - 基于多个选择值显示图像