Home > Web Front-end > JS Tutorial > body text

How to remove tags in javascript

藏色散人
Release: 2021-06-27 09:24:09
Original
4427 people have browsed it

How to remove tags in javascript: First create a corresponding code file; then remove all html tags through the "function delHtmlTag(str){...}" method.

How to remove tags in javascript

The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.

How to remove tags in javascript

js regular matching (remove html tags)

Get the link address on the webpage:

string matchString = @"<a[^>]+href=\s*(?:&#39;(?<href>^&#39;]+)&#39;|""(?<href>[^""]+)""|(?<href>[^>\s]+))\s*[^>]*>";
Copy after login

Get the title of the webpage:

string matchString = @"<title>(?<title>.*)</title>";
Copy after login

Remove all html tags in the web page:

string temp = Regex.Replace(html, "<[^>]*>", ""); //html是一个要去除html标记的文档
Copy after login
string matchString = @"<title>([\S\s\t]*?)</title>";
Copy after login

js function to remove all html tags:

function delHtmlTag(str)
{
      return str.replace(/<[^>]+>/g,"");//去掉所有的html标记
}
Copy after login

Count word count

t = $(&#39;.remarktext&#39;).html().replace(/<[^>]+>/g,"").length;
Copy after login

[Recommendation:javascript advanced tutorial

The above is the detailed content of How to remove tags in javascript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!