part of HTML; 2. Add "charset="gb2312" or "charset="utf-" to the

Home  >  Article  >  Web Front-end  >  What to do if alert is garbled in javascript

What to do if alert is garbled in javascript

藏色散人
藏色散人Original
2023-02-10 09:40:542645browse

Solution to garbled alert code in JavaScript: 1. Add "charset=utf-8"" to the

part of the HTML; 2. Add "charset="gb2312" to the <script> tag ” or “charset="utf-8""; 3. Change the saving encoding of the js external script to utf8. </script>

What to do if alert is garbled in javascript

## The operating environment of this tutorial: Windows 7 system, JavaScript version 1.8.5, Dell G3 computer.

What should I do if alert is garbled in javascript?

Alert in js external script Solution to Chinese garbled characters

I encountered a problem while working on a project. When I switched to using external references from the js script written in the html document, I found that the Chinese in alert() became Garbled characters.

The page already contains

Finally tried several methods, the following method was successful:

Method 1. Add

Method 2. Add

charset="gb2312"# to the <script> tag </script>##Method 3. The most fundamental way is to change the saving encoding of the js external script to utf8: When opening it with the editor, click Save As and select Unicode UTF-8, as shown below:

What to do if alert is garbled in javascriptAbout the difference between signed and unsigned: When the signed UTF-8 encoded content is parsed by the browser, the browser can determine that UTF-8 encoding is used for parsing directly based on the signature. When there is no signature, the browser will make a judgment based on the encoding of the content. In short, the signature will be easier for the browser to parse with the correct encoding. (This paragraph is excerpted from: UTF-8 Signature and Not The difference between signatures)

    Tried unsuccessful methods:
  • 1. You can add charset="utf to the <script> tag -8". </script>

Recommended learning: "

JavaScript Video Tutorial

"

The above is the detailed content of What to do if alert is garbled in javascript. 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