作者:小怡的宝_594 | 来源:互联网 | 2023-09-09 08:18
问题描述:在一个index.html网页中,引入了jquery脚本,但是却出现错误,提示$isnotdefined<!DOCTYPEhtml&
问题描述:
在一个index.html网页中,引入了jquery脚本,但是却出现错误,提示$ is not defined
window.onload=function (){
console.log($); //$ is not defined
}
在控制台下,发现jquery返回的是乱码格式,所以才会出现上述错误。
![html网页中加载js脚本 下载下来是乱码(文件编码格式) html网页中加载js脚本 下载下来是乱码(文件编码格式)](https://img1.php1.cn/3cd4a/24ed6/b64/56c95fba63b53634.jpeg)
正常情况下,应该是这样的:
![html网页中加载js脚本 下载下来是乱码(文件编码格式) html网页中加载js脚本 下载下来是乱码(文件编码格式)](https://img1.php1.cn/3cd4a/24ed6/b64/fdd999d827612fea.jpeg)
出现这种错误的原因就是文件的编码问题,在notePad中打开jquery文件发现,该文件是以UCS-2 Little Endian格式编码的,将其转为utf-8格式,就能正常加载了。
![html网页中加载js脚本 下载下来是乱码(文件编码格式) html网页中加载js脚本 下载下来是乱码(文件编码格式)](https://img1.php1.cn/3cd4a/24ed6/b64/60ddf5f5519318db.jpeg)
文件编码格式参考 :
http://www.cnblogs.com/joeblackzqq/archive/2011/04/11/2012005.html