JS to remove HTML tags in text __c language

Source: Internet
Author: User

Original source: http://blog.csdn.net/xuzengqiang2/article/details/41979733

Introduction: Given that the text is the data that is fetched from the rich editor, sometimes we may not need to display the format, so we need to remove the HTML tags and just need the text.

Mode one: Use Innertext,jquery to use text ()

InnerText will automatically remove HTML tags

<span class= ' Content_hidden ' style= ' display:none ' >${info.content}</span> <div ' class= '
ID = "Content_div" style= "Height:auto"; >
	Introduction £ <span id= "content_body" ></span>
</div>
Then set the value through JS:

$ ("#content_body"). Text ($ (". Content_hidden"). Text ());

Mode two: Use regular expressions to delete HTML tags:

function Delhtmltag (str) {return
  str.replace (/<[^>]+>/g, "");//Remove all HTML tags
} 
$ ("#content_ Body "). Text (Delhtmltag (" ${info.content} "));

And so on .....

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.