]+>/g" to replace the html tag, the syntax format is "stringObject.replace(/<[^<>]+>/g" ,'')". replace() can replace a substring that matches a regular expression."/> ]+>/g" to replace the html tag, the syntax format is "stringObject.replace(/<[^<>]+>/g" ,'')". replace() can replace a substring that matches a regular expression.">

Home  >  Article  >  Web Front-end  >  How to replace html tags with js

How to replace html tags with js

青灯夜游
青灯夜游Original
2021-05-27 17:22:184304browse

In js, you can use the replace() function with the regular expression "/3a01c64e1c68ffd528982950ceef0224] >/g" to replace the html tag, the syntax format is "stringObject.replace(/< ;[^a8093152e673feb7aba1828c43532094] >/g,'')". replace() can replace a substring that matches a regular expression.

How to replace html tags with js

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

js replaces html tags

      function  filter(text) {
            var reg = /<[^<>]+>/g;//1、全局匹配g肯定忘记写,2、<>标签中不能包含标签实现过滤HTML标签
            text = text.replace(reg, &#39;&#39;);//替换HTML标签
            return text;
        };

Related function description:

replace() method is used to replace some characters in a string Some other characters, or replace a substring that matches a regular expression.

Syntax

stringObject.replace(regexp/substr,replacement)
Parameters Description
regexp/substr

Required. A RegExp object that specifies the substring or pattern to be replaced.

Note that if the value is a string, it is retrieved as a literal text pattern, rather than first being converted to a RegExp object.

replacement Required. A string value. Specifies functions for replacing text or generating replacement text.

Return value:

  • A new string that replaces the first match or all matches of regexp with replacement Got it later.

Supplement: Use filters to filter rich text data in angularJS

app.filter(&#39;qxhtml&#39;, function () {
        return function (text) {
            var reg = /<[^<>]+>/g;
            text = text.replace(reg, &#39;&#39;);
            text = text.replace(/ /ig, &#39;&#39;);
            if (text.length > 50) {
                text = text.substring(0, 50) + "...";
            }
            return text;
        };
    });

Use filters

<div class="desc">
     {{y.Description| qxhtml}}
</div>

More programming For related knowledge, please visit: programming video! !

The above is the detailed content of How to replace html tags with js. 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