Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to solve the problem of garbled codes in javascript display

Shulou Source: shulou.com Published: 2022-05-31 11:46:55 10月03日 Update

This article mainly introduces the javascript display Chinese is garbled how to solve the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that after reading this javascript shows that Chinese is garbled how to solve the article will have a harvest, let's take a look.

Javascript display Chinese is garbled solutions: 1, select and the original document encoding consistent with the encoding way to view; 2, in the reference XX.js page "display" plus XX.js file encoding.

This article operating environment: windows7 system, javascript1.8.5 version, Dell G3 computer.

What if javascript shows Chinese garbled code? how to solve js Chinese garbled code?

① .js file shows garbled codes in Chinese

When Javascript files are edited and saved by XX.js, there is a coding scheme (such as GBK). When the encoding used when opening the file (such as UTF-8) is inconsistent with the coding scheme when saving, garbled Chinese will appear.

Solution:

(1) when opening and browsing with an editor, select the same encoding method as the original file encoding (such as GBK), and there will be no garbled code.

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

Garbled Chinese fields in JavaScript in the pages of ② website

The Chinese display in XX.js is normal in eclipse or editor. Call XX.js on the page, and the Chinese field in the page result shows garbled code after execution.

Solution:

Add the encoding of the XX.js file to the page that references the XX.js to make it consistent with the encoding of the XX.js file itself (such as GBK).

Recommendations:

(1) when you create a new XX.js with Eclipse or Myeclipse for editing, it is recommended to change Text file encoding to UTF-8 first, and then edit and save it.

Note: the setting path of eclipse: Myeclispe Enterprise Workbench\ Files and Editors\ JavaScript\

(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) on the page referencing XX.js, "display" plus the encoding mode of XX.js file UTF-8.

This is the end of the article on "how to solve the problem of Chinese garbled in javascript display". Thank you for your reading! I believe you all have a certain understanding of the knowledge of "javascript shows that Chinese is garbled". If you want to learn more, you are welcome to follow the industry information channel.

Tags: Garbled coding Chinese file method page consistency scheme UTF-8 selection suggestion knowledge editor middle content field time article solution value Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Linux MySQL OPPO Reno Apple