Home Web Front-end JS Tutorial 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

May 28, 2018 pm 01:52 PM
alert javascript js

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 <head>< Add a <meta> tag to /head> and specify the HTML encoding format to be UTF-8. The code is as follows:

&lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=UTF-8&quot;&gt;
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!

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to implement an online speech recognition system using WebSocket and JavaScript How to implement an online speech recognition system using WebSocket and JavaScript Dec 17, 2023 pm 02:54 PM

How to implement an online speech recognition system using WebSocket and JavaScript

Recommended: Excellent JS open source face detection and recognition project Recommended: Excellent JS open source face detection and recognition project Apr 03, 2024 am 11:55 AM

Recommended: Excellent JS open source face detection and recognition project

Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS Dec 17, 2023 pm 06:55 PM

Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems WebSocket and JavaScript: key technologies for implementing real-time monitoring systems Dec 17, 2023 pm 05:30 PM

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems

How to implement an online reservation system using WebSocket and JavaScript How to implement an online reservation system using WebSocket and JavaScript Dec 17, 2023 am 09:39 AM

How to implement an online reservation system using WebSocket and JavaScript

PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts Dec 18, 2023 pm 03:39 PM

PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts

How to use JavaScript and WebSocket to implement a real-time online ordering system How to use JavaScript and WebSocket to implement a real-time online ordering system Dec 17, 2023 pm 12:09 PM

How to use JavaScript and WebSocket to implement a real-time online ordering system

JavaScript and WebSocket: Building an efficient real-time weather forecasting system JavaScript and WebSocket: Building an efficient real-time weather forecasting system Dec 17, 2023 pm 05:13 PM

JavaScript and WebSocket: Building an efficient real-time weather forecasting system

See all articles