Sometimes we will encounter the problem of JS Chinese garbled, mainly occurred in the case of a JS file.
When the page contains a JS file in Chinese output, in the page will appear garbled.
Workaround, add charset to the inclusion code, and match the page encoding.
<script charset= "gb2312" src= "/dotbbs_net/js/register.js" language= "Web Effects" ></script>
Analysis
See the Code
1.
2.
3. <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
4. <script type= "Text/javascript" src= "Text.js" ></script>
5.
6. <body>
7.
8. </body>
9.
If there is a statement in Chinese in the text.js, it will produce garbled characters.
In fact, is the second line of CharSet, the second line is mainly set the entire page character encoding way, in this case is UTF-8.
And in JS is a common GB2312 or GBK encoding method.
So will produce garbled.
Workaround:
In <script> this element, our most commonly used attribute is "type" or "language", there is a property is gradually forgotten by us, that is: CharSet. In the above example, we just specify the encoding of JS can be normal display of Chinese. The code is as follows
1.
2.
3. <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
4. <script type= "Text/javascript" src= "Text.js" charset= "GB2312" ></script>
5.
6. <body>
7.
8. </body>
9.
Note The final charset= of the third line, "Gb2312″."
If you use Dreamweaver to write JS, then recommend you to the preferences > New Document "When open an unspecified encoding of existing files to use" tick
Yes, do not save the garbled, a save can not return to the head