Home > Web Front-end > JS Tutorial > body text

Detailed explanation to solve the problem of alert pop-up box displaying Chinese garbled characters when JavaScript is introduced

巴扎黑
Release: 2018-05-28 13:52:58
Original
3519 people have browsed it

When I introduced a JavaScript file into HTML today and ran it, the Chinese text in the alert box that popped up was garbled. How to solve this problem? The following editor brings you a solution to the problem that the alert pop-up box displays garbled Chinese characters when JavaScript is introduced. Let’s take a look.

Today, when a JavaScript file is introduced into HTML and run, the alert pop-up box displays Chinese characters as Garbled characters.

After investigation, there are two possibilities:

1. JavaScript and HTML file encoding methods are different

Method: Specify the character set as gb2312 in the code that introduces JavaScript. The code is as follows:

<script charset="gb2312" type="text/javascript" language="javascript" src="javascript.js"></script>
Copy after login

2. The encoding method of HTML does not support the display of Chinese

Method: In < Add a tag to /head> and specify the HTML encoding format to be UTF-8. The code is as follows:

<meta http-equiv="content-type" content="text/html; charset=UTF-8">
Copy after login

The above is the detailed content of Detailed explanation to solve the problem of alert pop-up box displaying Chinese garbled characters when JavaScript is introduced. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!