Article introduction of Wulin.com (www.vevb.com): Commonly used encoding conversion of HTML.
This code snippet is provided by the web teaching website. var encoding = (function () { function ToASCII(str) {return this.ToNormal(str).replace(/[^/u0000-/u00FF]/g, function () { return escape(arguments[0]).replace(/(?:%u)([0-9a-f]{4})/gi, /$1;) }); } function ToUnicode(str) {return this.ToNormal(str).replace(/[^/u0000-/u00FF]/g, function () { return escape(arguments[0]).replace(/(?:%u)([0-9a-f]{4})/gi, //u$1) }); } function ToNormal(str) {return str.replace(/(?:)([0-9a-f]{4});|(?://u)([0-9a-f]{4})/gi, function () { return unescape(%u + (arguments[1] || arguments[2])); }); } function ToCss(str) {return this.ToNormal(str).replace(/[^/u0000-/u00FF]/g, function () { return escape(arguments[0]).replace(/(?:%u)([0-9a-f]{4})/gi, //$1) }); } return {ToASCII: ToASCII,ToUnicode: ToUnicode,ToNormal: ToNormal,ToCss: ToCss }; })(); console.log(encoding.ToASCII(安体)); console.log(encoding.ToUnicode(安体)); console.log(encoding.ToNormal(安体)); console.log(encoding.ToUnicode(安体)); console.log(encoding.ToUnicode(安体)); console.log(encoding.ToNormal(安体)); console.log(encoding.ToUnicode(安体)); console.log(encoding.ToCss('Arial , Helvetica , Song font, sans-serif'));