Home>Article>Web Front-end> How to solve javascript garbled problem

How to solve javascript garbled problem

藏色散人
藏色散人 Original
2021-03-30 10:54:50 71517browse

Solution to JavaScript garbled code: 1. Open it with an editor and select the encoding method that is consistent with the original file encoding to view; 2. Select the garbled "XX.js" and then change the encoding when saving; 3. Save in UTF-8 encoding, etc.

How to solve javascript garbled problem

The operating environment of this article: Windows 7 system, JavaScript version 1.8.5, DELL G3 computer.

JS Chinese garbled solution: Set charset=utf-8 and complete.

①.js file Chinese display garbled Javascript file XX.js has an encoding scheme (such as GBK) when editing and saving. When opening the file, the encoding (such as UTF-8) used is inconsistent with the encoding scheme when saving. , Chinese display garbled characters will appear.

Solution:

(1) When opening and browsing with an editor, select the encoding method consistent with the original file encoding (such as GBK) to view, then garbled characters will not appear;

(2) Select the garbled XX.js in the package explorer in eclipse, select properties in the right-click menu, and select the encoding (such as GBK) when editing and saving with XX.js in Text file encoding, and it can be displayed normally. .

②The Chinese field in JavaScript in the website page is garbled. In eclipse or the editor, the Chinese in XX.js is displayed normally. When XX.js is called on the page, the Chinese field in the page result is garbled after execution.

Solution: "Display" on the page that references XX.js and add the encoding method of the XX.js file to make it consistent with the encoding method of the XX.js file itself (such as GBK).

1) Use Eclipse or Myeclipse to create a new XX .js, when editing, it is recommended to change the Textfile encoding to UTF-8 first, then edit and save.

2) Use a text document or other editor to edit and save XX.js. It is recommended to save it in UTF-8 encoding.

3) "Display" and add the encoding method UTF-8 of the XX.js file on the page that references XX.js.

[Recommended learning:js basic tutorial]

The above is the detailed content of How to solve javascript garbled problem. For more information, please follow other related articles on the PHP Chinese website!

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