Four JS filter HTML tag code

Source: Internet
Author: User
Keywords Web page production Ajax javascript
Tags ajax code codes function html http javascript join

Article provides 14 JS filter HTML tag Code Oh, they use a variety of methods to filter the HTML tag code, these codes are very good oh, well, let's see.
<!doctype HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/ Xhtml1-transitional.dtd ""
<html xmlns= "http://www.jzread.com/1999/xhtml"
<head>
< Meta http-equiv= "Content-type" content= "HTML; charset=gb2312 "/>
<title>js Filter HTML tags </title>
<script language=" web Effects "
function Covertfromxmltag (value) {
    value = Value.split ("&"). Join ("&amp;");
    value = Value.split ("<"). Join ("&lt;");
    value = Value.split (">"). Join ("&gt;");
    value = Value.split (' "). Join (" &quot; ");
    value = Value.split (""). Join ("&nbsp;");
    value = Value.split ("R"). Join ("");
    value = Value.split ("n"). Join ("<br/>");
    return value;
}

function escapehtml (value) {
With (Document.createelement ("div")) {
AppendChild (document.createTextNode (value));
return Innerhtml.replace (/"G, &quot;");
}
}

function JSP tutorial asshtml ()
{
str = "<a href=" xxx.asp tutorial "><div>1234567</div>89</a>";
Alert (Str.replace (/<.*?>/g, ""));
}

function HTMLEncode (str) {
str = str.replace (/&/g, ' &amp; ');
str = str.replace (/</g, ' &lt; ');
str = str.replace (/>/g, ' &gt; ');
str = str.replace (/(?: t| |v|r) *n/g, ' <br/> ');
str = str.replace (/g, ' &nbsp; ');
str = str.replace (/t/g, ' &nbsp; &nbsp; ');
str = str.replace (/x22/g, ' &quot; ');
str = str.replace (/x27/g, ' & #39; ');
return str;
}

</script>
</head>

<body>
</body>
</html>

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.