{"id":4932,"date":"2023-01-05T11:21:10","date_gmt":"2023-01-05T03:21:10","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=4932"},"modified":"2023-01-05T11:21:10","modified_gmt":"2023-01-05T03:21:10","slug":"%e5%ad%b8%e7%bf%92typescript%e4%b8%ad%e5%ad%97%e4%b8%b2%e7%9a%84html%e7%b7%a8%e7%a2%bc-%e8%a7%a3%e7%a2%bc","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e5%ad%b8%e7%bf%92typescript%e4%b8%ad%e5%ad%97%e4%b8%b2%e7%9a%84html%e7%b7%a8%e7%a2%bc-%e8%a7%a3%e7%a2%bc\/","title":{"rendered":"\u5b78\u7fd2TypeScript\u4e2d\u5b57\u4e32\u7684HTML\u7de8\u78bc\/\u89e3\u78bc"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, HTML, Encoding, Decoding\"><\/p>\n<h1>TypeScript \u5b57\u4e32\u7684\u6c42 HTML \u7de8\u78bc\/\u89e3\u78bc(String HTML Encoding\/Decoding)<\/h1>\n<p>TypeScript \u662f\u4e00\u7a2e JavaScript \u7684\u8d85\u96c6\uff0c\u5b83\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u958b\u767c\u51fa\u66f4\u9ad8\u8cea\u91cf\u7684\u7a0b\u5f0f\u78bc\u3002\u5728 TypeScript \u4e2d\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u4f7f\u7528\u5b57\u4e32\u7684\u6c42 HTML \u7de8\u78bc\/\u89e3\u78bc\u529f\u80fd\u4f86\u5c0d HTML \u6587\u672c\u9032\u884c\u7de8\u78bc\u548c\u89e3\u78bc\u3002<\/p>\n<p>\u5b57\u4e32\u7684\u6c42 HTML \u7de8\u78bc\/\u89e3\u78bc\u529f\u80fd\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5c07 HTML \u6587\u672c\u7de8\u78bc\u6210\u53ef\u4ee5\u5728\u7db2\u9801\u4e0a\u986f\u793a\u7684\u6587\u672c\uff0c\u800c\u4e0d\u6703\u5c0e\u81f4\u7db2\u9801\u51fa\u73fe\u932f\u8aa4\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4e00\u500b HTML \u6587\u672c\u4e2d\u5305\u542b\u4e86\u7279\u6b8a\u5b57\u5143\uff0c\u4f8b\u5982 &lt; \u548c >\uff0c\u5247\u53ef\u4ee5\u4f7f\u7528\u5b57\u4e32\u7684\u6c42 HTML \u7de8\u78bc\/\u89e3\u78bc\u529f\u80fd\u5c07\u5176\u7de8\u78bc\u70ba &lt; \u548c &gt;\uff0c\u4ee5\u4fbf\u5728\u7db2\u9801\u4e0a\u6b63\u78ba\u986f\u793a\u3002<\/p>\n<p>\u53e6\u5916\uff0c\u5b57\u4e32\u7684\u6c42 HTML \u7de8\u78bc\/\u89e3\u78bc\u529f\u80fd\u9084\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5c07 HTML \u6587\u672c\u89e3\u78bc\u6210\u53ef\u4ee5\u5728\u7db2\u9801\u4e0a\u6b63\u78ba\u986f\u793a\u7684\u6587\u672c\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4e00\u500b HTML \u6587\u672c\u4e2d\u5305\u542b\u4e86\u7279\u6b8a\u5b57\u5143\uff0c\u4f8b\u5982 &lt; \u548c &gt;\uff0c\u5247\u53ef\u4ee5\u4f7f\u7528\u5b57\u4e32\u7684\u6c42 HTML \u7de8\u78bc\/\u89e3\u78bc\u529f\u80fd\u5c07\u5176\u89e3\u78bc\u70ba &lt; \u548c >\uff0c\u4ee5\u4fbf\u5728\u7db2\u9801\u4e0a\u6b63\u78ba\u986f\u793a\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u4e00\u500b\u4f7f\u7528 TypeScript \u4f86\u7de8\u78bc\/\u89e3\u78bc HTML \u6587\u672c\u7684\u7bc4\u4f8b\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet htmlText = \"This is an example of HTML text.<\/p>\";\n\n\/\/ Encode the HTML text\nlet encodedText = String.htmlEncode(htmlText);\nconsole.log(encodedText); \/\/ Outputs: &lt;p&gt;This is an example of HTML text.&lt;\/p&gt;\n\n\/\/ Decode the HTML text\nlet decodedText = String.htmlDecode(encodedText);\nconsole.log(decodedText); \/\/ Outputs: <p>This is an example of HTML text.\n<\/pre>\n<p>\u4e0a\u9762\u7684\u7bc4\u4f8b\u4e2d\uff0c\u6211\u5011\u4f7f\u7528 <code>String.htmlEncode()<\/code> \u65b9\u6cd5\u5c07 HTML \u6587\u672c\u7de8\u78bc\uff0c\u4e26\u4f7f\u7528 <code>String.htmlDecode()<\/code> \u65b9\u6cd5\u5c07 HTML \u6587\u672c\u89e3\u78bc\u3002<\/p>\n<p>\u5b57\u4e32\u7684\u6c42 HTML \u7de8\u78bc\/\u89e3\u78bc\u529f\u80fd\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u5c0d HTML \u6587\u672c\u9032\u884c\u7de8\u78bc\u548c\u89e3\u78bc\uff0c\u4ee5\u4fbf\u5728\u7db2\u9801\u4e0a\u6b63\u78ba\u986f\u793a\u3002\u9019\u5c0d\u65bc\u958b\u767c\u8005\u4f86\u8aaa\u662f\u975e\u5e38\u6709\u7528\u7684\uff0c\u56e0\u70ba\u5b83\u53ef\u4ee5\u8b93\u4ed6\u5011\u66f4\u5bb9\u6613\u5730\u5c0d HTML \u6587\u672c\u9032\u884c\u7de8\u78bc\u548c\u89e3\u78bc\uff0c\u800c\u4e0d\u9700\u8981\u81ea\u5df1\u5beb\u51fa\u7de8\u78bc\/\u89e3\u78bc\u7684\u7a0b\u5f0f\u78bc\u3002<\/p>\n<p><!--more--><\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>TypeScript \u63d0\u4f9b\u4e86\u5b57\u4e32\u7684\u6c42 HTML \u7de8\u78bc\/\u89e3\u78bc\u529f\u80fd\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5c0d HTML \u6587\u672c\u9032\u884c\u7de8\u78bc\u548c\u89e3\u78bc\uff0c\u4ee5\u4fbf\u5728\u7db2\u9801\u4e0a\u6b63\u78ba\u986f\u793a\u3002\u9019\u5c0d\u65bc\u958b\u767c\u8005\u4f86\u8aaa\u662f\u975e\u5e38\u6709\u7528\u7684\uff0c\u56e0\u70ba\u5b83\u53ef\u4ee5\u8b93\u4ed6\u5011\u66f4\u5bb9\u6613\u5730\u5c0d HTML \u6587\u672c\u9032\u884c\u7de8\u78bc\u548c\u89e3\u78bc\uff0c\u800c\u4e0d\u9700\u8981\u81ea\u5df1\u5beb\u51fa\u7de8\u78bc\/\u89e3\u78bc\u7684\u7a0b\u5f0f\u78bc\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1a\u5b78\u7fd2TypeScript\u4e2d\u5b57\u4e32\u7684HTML\u7de8\u78bc\/\u89e3\u78bc\uff0c\u53ef\u4ee5\u8b93\u4f60\u66f4\u6709\u6548\u7387\u5730\u5c0d\u7db2\u9801\u5167\u5bb9\u9032\u884c\u7de8\u78bc\u548c\u89e3\u78bc\uff0c\u63d0\u9ad8\u7db2\u9801\u958b\u767c\u7684\u6548\u7387\u3002\u672c\u6587\u5c07\u4ecb\u7d39TypeScript\u4e2d\u5b57\u4e32\u7684HTML\u7de8\u78bc\/\u89e3\u78bc\u7684\u57fa\u672c\u6982\u5ff5\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u5b83\u4f86\u63d0\u9ad8\u7db2\u9801\u958b\u767c\u7684\u6548\u7387\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[187],"tags":[186],"class_list":["post-4932","post","type-post","status-publish","format-standard","hentry","category-typescript","tag-typescript"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1hy","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4932","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=4932"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4932\/revisions"}],"predecessor-version":[{"id":4933,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4932\/revisions\/4933"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=4932"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=4932"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=4932"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}