html网页中加载js脚本 下载下来是乱码(文件编码格式)
问题描述:
在一个index.html网页中,引入了jquery脚本,但是却出现错误,提示$ is not defined
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src='js/jquery-1.9.1.min.js'></script>
</head>
<body>
window.onload=function (){
console.log($); //$ is not defined
}
</body>
</html>
在控制台下,发现jquery返回的是乱码格式,所以才会出现上述错误。

正常情况下,应该是这样的:

出现这种错误的原因就是文件的编码问题,在notePad中打开jquery文件发现,该文件是以UCS-2 Little Endian格式编码的,将其转为utf-8格式,就能正常加载了。

文件编码格式参考 :
http://www.cnblogs.com/joeblackzqq/archive/2011/04/11/2012005.html

浙公网安备 33010602011771号