search
HomeWeb Front-endJS TutorialWhat should I do if the Chinese characters displayed by JavaScript are garbled?

The solution to the problem that javascript displays garbled Chinese characters: 1. Select the encoding method that is consistent with the original file encoding to view; 2. "Display" and add the encoding method of the XX.js file on the page that references XX.js .

What should I do if the Chinese characters displayed by JavaScript are garbled?

The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.

What should I do if the Chinese characters displayed in JavaScript are garbled? How to solve the problem of Chinese garbled characters in js?

①.js file displays garbled characters in Chinese

There is an encoding scheme (such as GBK) when editing and saving Javascript file XX.js. The encoding used when opening the file (such as UTF-8) is inconsistent with the encoding scheme when saving, garbled Chinese 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 there will be no garbled characters;

(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, then it can be displayed normally ;

②The Chinese field in the JavaScript in the website page is garbled

The Chinese in XX.js is displayed normally in eclipse or the editor, call XX.js on the page, and execute The Chinese field in the results on the subsequent page displays garbled characters.

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) remains consistent.

 <script type="text/javascript" language="JavaScript" src="/js/XX.js" charset=“GBK”></script>

Suggestions:

(1) When using Eclipse or Myeclipse to create a new XX.js and edit it, it is recommended to change the Text file encoding to UTF-8 first, and then edit and save it.

Note: eclipse setting path: 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 use UTF-8 encoding method to save.

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

   <script type="text/javascript" language="JavaScript" src="/js/XX.js" charset=“utf-8”></script>

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of What should I do if the Chinese characters displayed by JavaScript are garbled?. 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
React Context API Practical Practice: Optimize multi-state management and component communicationReact Context API Practical Practice: Optimize multi-state management and component communicationAug 26, 2025 pm 01:24 PM

This tutorial explores in-depth how to use the React Context API to effectively manage multiple related useState states in React applications, especially for scenarios such as filters, to solve the problem of prop drilling between components. The article will demonstrate in detail how to create, provide and consume contexts through two different implementation solutions, thereby realizing decoupling and state sharing between components and improving the maintainability and readability of code.

Implement a method to submit a form within a specific DIV without refreshing the entire pageImplement a method to submit a form within a specific DIV without refreshing the entire pageAug 26, 2025 pm 01:21 PM

This article aims to provide a solution to submit a form to a specific element in the page without refreshing the entire page. We will explore the use of JavaScript to intercept form submission events, send form data to the server through Ajax, and update the results returned by the server to the specified area, thereby achieving the effect of local updates.

Master the logical processing of interactive button state in JavaScriptMaster the logical processing of interactive button state in JavaScriptAug 26, 2025 pm 01:15 PM

This article explores in-depth how to effectively manage complex user interface button status using JavaScript, especially with the "Like/Cancel" feature as an example. We will analyze two main implementation strategies: loop-based iterative state update and functional programming using the array reduce method. Through detailed code examples and logical parsing, the article aims to help developers understand state flow rules and choose the best solution for their scenarios, thus achieving accurate and robust button interaction logic.

Tutorial on implementing front-end page option filtering functionTutorial on implementing front-end page option filtering functionAug 26, 2025 pm 01:09 PM

This article aims to guide developers how to implement a front-end-based option filtering function. We will use an example of school information display to explain in detail how to use JavaScript and CSS to dynamically display and hide page elements, thereby achieving the ability to filter schools by category. This article will cover data structure design, HTML structure construction, JavaScript logic writing, and CSS style setting, etc., to help readers quickly master the implementation methods of front-end filtering functions.

React Keys: Efficiently use Fragment for list rendering in static arraysReact Keys: Efficiently use Fragment for list rendering in static arraysAug 26, 2025 pm 01:06 PM

This article aims to solve the warning issue caused by the lack of key attribute in React when mapping static arrays to HTML tags. We will dig deep into the principles of React Keys, analyze the misunderstanding of placing keys on elements inside Fragment, and provide solutions to correctly apply keys to React.Fragment, while discussing under what circumstances can be used as keys to optimize list rendering performance and avoid potential errors.

TestCafe: Solve the problem that elements cannot be retrieved in userVariablesTestCafe: Solve the problem that elements cannot be retrieved in userVariablesAug 26, 2025 pm 01:03 PM

This article aims to solve the problem that when using userVariables configuration in TestCafe, the variable values ​​cannot be correctly obtained due to typos. By analyzing problem code and solutions, help developers avoid similar errors and use the userVariables function correctly.

JavaScript module export name extraction: a simple tutorial to use the AST parserJavaScript module export name extraction: a simple tutorial to use the AST parserAug 26, 2025 pm 12:57 PM

This article aims to provide an easy way to extract all exported names from the text of a JavaScript ES module. Since it is more complicated to perform lexical analysis directly, this article recommends using ready-made JavaScript parsers (such as Acorn, Esprima or Babel) to parse the code into an abstract syntax tree (AST), and then traverse AST to extract the export information. AST Explorer allows you to easily experiment with different parsers and observe the generated AST structure to better understand and extract the required information.

Use Nuxt 3 to provide user uploaded files: Build API endpointsUse Nuxt 3 to provide user uploaded files: Build API endpointsAug 26, 2025 pm 12:51 PM

This document is intended to resolve the problem that users cannot access directly through the public directory after uploading files in Nuxt 3 applications. We will explore the features of the public directory and provide solutions to build API endpoints to provide these files safely and efficiently.

See all articles

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Hot Topics