Home  >  Article  >  Web Front-end  >  Detailed explanation to solve the problem of alert pop-up box displaying Chinese garbled characters when JavaScript is introduced

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

巴扎黑
巴扎黑Original
2018-05-28 13:52:583559browse

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>

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

Method: In 93f0f5c25f18dab9d176bd4f6de5d30e284fbd28812df58f210573eaeae183e4 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">

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!

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