• Welcome to Baben's blog that year. I'm glad to meet you at the right age!
  • Due to the theme, the QQ login partner displays the default avatar in the comments. Please go to the personal center to upload the avatar again.

Js matches the style in the html tag

Code Notes barben Four years ago (2020-10-09) 3678 views 0 comments

There is a news content module in the project, which is a piece of html text sent from the back end. I decided to use v-html rendering on the front end.

 A piece of html content from the back end

However, it is really ridiculous to directly render the tag with style on this page!

 Regularly match the style in the html tag and clear it

Regularly match the style in the html tag and delete it with replace

 Let content="<p style='color: # 00afef; '>Next time</p>"; content = content.replace(/style\s*=\s*('[^']*'|"[^"]*")/ig, ""); //Or you can first remove the double quotation marks and then remove the single quotation marks // content = content.replace(/style="[^\"]*?"/ig, "").replace(/style='[^\']*?'/ig, "");

 


Eight blogs that year, we have been
If the author does not indicate that it is an original article, please indicate the link and source of this article for reprinting
Js matches the style in the html tag- https://www.barben.cn/code/907.html
Like( ten )
Post my comments
Cancel comment
expression Mapping Bold Strike through Center Italic

You need to bring your nickname and email with you in the review of Eight Books that year!

  • Nickname (required)
  • Email (required)
  • website