最近、あるプロジェクトに取り組んでいます。ページでは Cookie が使用されているため、ユーザーのブラウザが Cookie をサポートしているかどうかを確認し、ブラウザの Cookie 機能を有効にする方法をユーザーに表示する必要があります。同時に、プロジェクト全体を中国語、ベトナム語、日本語、英語などの多言語サポートで構成する必要があるため、言語構成ファイルが必要です。このプロジェクトでは、jQuery を使用して XML 言語構成ファイルを解析および読み取り、言語スケジューリングを実装します。これは、jQuery の XML ファイルを解析して読み取る機能のテスト ソース コードです。
ディレクトリ構造:
main.css ファイルコード:
Final result display:
No need to say more, the code is marked with very detailed comments.
But during the test, I also encountered one or two problems. First of all, the encoding format of the XML file must be UTF-8, that is, must be ensured, otherwise garbled characters will appear. Because jQuery's Ajax transmission data is encoded in UTF-8.
The second issue is about the encoding of JS files. Logically speaking, Chinese characters should not appear in JS files. In the test, I added a test for Chinese, such as the code snippet $("#Message_error").text("Error loading XML document (error loading XML file)" xml);, which means that the XML cannot be parsed correctly or cannot be found. When testing the file, I found that the Chinese characters "Error loading XML file" were always displayed as garbled characters. It took me a long time to find out that it was a problem with the encoding of the JS file itself. After searching online for a long time, no one clearly explained the solution. Even if there was, it did not solve the root cause of the garbled code. Besides, most people were talking nonsense. In one post They go around and around and use it to harm others without even testing it themselves. Finally, I fumbled for more than an hour and finally solved the JS file encoding problem, and also solved the garbled problem of jQuery.html() function and jQuery.text() function when transmitting Chinese.
Regarding the solution to the garbled problem of jQuery.html() function and jQuery.text() function when transmitting Chinese, please pay attention to my other article "JS file itself encoding conversion "
File package download