Home >Web Front-end >JS Tutorial >Analysis and solutions to refer to external js garbled code_javascript skills
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