The html string constructed in the background is uploaded to the foreground string for transcoding (html) processing, and the foreground string

Source: Internet
Author: User

The html string constructed in the background is uploaded to the foreground string for transcoding (html) processing, and the foreground string

The knowledge lies in summary, so write down it!

 

For example, the background html string is

Var htmlStr = "background html string ";

Transcoding

Var html code = decodeHtml (htmlStr );

You just need to call the following js method.

Function decodeHtml (s) {var HTML_DECODE = {"& lt;": "<", "& gt;": ">", "& amp ;":"&", "& nbsp;": "", "& quot;": "\" "," & copy; ":" "// Add more }; var REGX_HTML_ENCODE =/"| & | '| <|> | [\ x00-\ x20] | [\ x7F-\ xFF] | [\ u0100-\ u2700]/g; var REGX_HTML_DECODE =/& \ w +; | & # (\ d +);/g; var REGX_TRIM =/(^ \ s *) | (\ s * $) /g; s = (s! = Undefined )? S: ""; return (typeof s! = "String ")? S: s. replace (REGX_HTML_DECODE, function ($0, $1) {var c = HTML_DECODE [$0]; if (c = undefined) {// Maybe is Entity Number if (! IsNaN ($1) {c = String. fromCharCode ($1 = 160 )? 32: $1) ;}else {c = $0 ;}} return c ;}; View Code

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.