Home >Web Front-end >JS Tutorial >Analysis and solutions to refer to external js garbled code_javascript skills

Analysis and solutions to refer to external js garbled code_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:37:271488browse

In web development, we generally inevitably use js. We can put the js code directly in the page by using js internally. But in order to "slim down" the page, we usually put the js code externally and then reference it through src. At this time we need to pay attention to a problem: encoding problem. If the web page and js use different encodings, garbled characters will appear at this time. (You don’t need to pay attention to encoding issues when using js internally, because they use the same encoding)

For most web pages, we generally use the following two encodings: UTF-8, GB2312. So we only need to agree with the page and js encoding to solve the garbled code problem:
For GBK page reference JavaScript files encoded as UTF-8 encoding, if there is a garbled code problem, you can use the following code to solve it

Copy code The code is as follows:

<script type=”text/javascript” src=”test.js” charset=” utf-8″>

The problem of garbled JavaScript files encoded as GBK is also introduced in UTF-8 pages. You can use the following method:
Copy code The code is as follows:

<script type=”text/javascript” src=”test.js” charset=” gb2312″>

This method is used when Chinese characters appear in js files, and other characters that are prone to errors in GBK and UTF-8 encoding. For pure English is no longer needed. If it's for insurance, you can add it...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn