Today's project encountered the need to use JavaScript escape encoding Chinese characters and then use unescape decoding, the test Code section when there is a garbled situation.
The details are as follows:
First, open the test page with EditPlus test.html and edit the following HTML code:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
Page printout:
%ufffd%u0171%ufffd%u05ae%ufffd%ufffd
At this point you can see that the situation is not right, the number of characters corresponding to the character is already wrong!
Use the following code to test the unescape decoded characters:
var relstr=unescape ("%ufffd%u0171%ufffd%u05ae%ufffd%ufffd");
document.write (RELSTR);
There are garbled: Ű֮
Workaround:
With Dreamweaver open test.html file, found the problem!
The original part of the
var teststr=escape ("cloud-dwelling community");
into a
var teststr=escape ("Ű֮");
Visible is caused by the editor's initial encoding!
In Dreamweaver, the Chinese character is changed back, the test.html is rerun, and the corresponding code is obtained:
Then use Unescape to decode:
var relstr=unescape ("%u811a%u672c%u4e4b%u5bb6");
document.write (RELSTR);
Get the original correct Chinese characters: cloud-dwelling community!