在线
客服

在线客服
尊敬的客户,我们24小时竭诚为您服务 公司总机: 0755-83312037 (32条线)

客服
热线

0755-83312037 (32条线)
7*24小时客服服务热线

?

关注
微信

关注官方微信
TOP

返回
顶部

HTML常用编码转换

发布时间:2019-04-13浏览次数:1010 <p> </p> <table style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0"><tbody><tr> <td style="WORD-WRAP: break-word" bgcolor="#fdfddf"> <font color="#ff0000">网页制作Webjx文章简介:</font><font color="#000000">HTML常用编码转换。</font> </td> </tr></tbody></table>本代码片段由网页教学网提供。 <pre>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("宋\u4F53")); console.log(encoding.ToUnicode("宋体")); console.log(encoding.ToCss('Arial , Helvetica ,"宋体", sans-serif'));</pre>