In web development, we usually use js inevitably. We can place js Code directly on the page to use js internally. But in order to make the page "slim", we usually put the js Code outside and reference it through src. At this time, we need to pay attention to the encoding problem. If JavaScript code is used for web pages, garbled characters may occur. (You do not need to pay attention to encoding when using js internally, because they use the same encoding)
For most web pages, we generally use the following two types of encoding: UTF-8, GB2312. Therefore, we only need to agree to the page and js Code to solve the garbled problem:
For GBK page reference code for UTF-8-Encoded JavaScript files if garbled problem, you can use the following code to solve
[Javascript] view plaincopyprint?
<Script type = "text/javascript" src = "test. js" charset = "UTF-8"> </script>
Introduce the garbled JavaScript file encoded as gbk in the UTF-8 page, you can use the following method:
[Html] view plaincopyprint?
<Script type = "text/javascript" src = "test. js" charset = "gb2312"> </script>
This method is for the js file appears in Chinese characters, and other easily caused in GBK and UTF-8 Encoding Error characters when using, for pure English do not need. If you want insurance, you can add ....
Author: chenssy