Home>Article>Web Front-end> How to remove tags in javascript

How to remove tags in javascript

藏色散人
藏色散人 Original
2021-06-27 09:24:09 4401browse

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 = @"]+href=\s*(?:'(?^']+)'|""(?[^""]+)""|(?[^>\s]+))\s*[^>]*>";

Get the title of the webpage:

string matchString = @"(?<title>.*)";

Remove all html tags in the web page:

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

js function to remove all html tags:

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

Count word count

t = $('.remarktext').html().replace(/<[^>]+>/g,"").length;

[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!

Statement:
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