为了账号安全,请及时绑定邮箱和手机立即绑定

如何在js中读取嵌入的html字符串?

如何在js中读取嵌入的html字符串?

月关宝盒 2022-01-07 16:16:05
我有一个字符串,需要将其转换为可读形式。预期输出附在底部。这基本上是html在 js 中读取字符串。我浏览了各种文章,但没有找到任何东西。如何读取此字符串以生成预期的输出。我试过这个,但不太奏效。我不替换Enter字符串中的字符。str = str.replace(/<\/?[^>]+(>|$)/g, '');预期输出:This course carries&nbsp;4 hours of Continuing Professional Development (CPD) credits.&nbsp;&nbsp;In support of the Journalism Now Scholar Programme, for a limited time, there is no charge for the course certificate.&nbsp;&nbsp;&nbsp;COURSE OVERVIEW&nbsp;This course will help give your use of social media a journalistic purpose.&nbsp; You'll learn how to find good stories, whether you're using Facebook, Twitter, Instagram, or any other form of social media. Once you've completed the course, you will be able to understand each of the social media platforms - they all have their own system which you will be able to get to grips with and you will discover how to refine your searches so that you get the information you need more easily.&nbsp; The course will help you become a good 'social listener' by giving you the best hashtags to use, as well as the best keywords.&nbsp;"The content is really good, I enjoyed it because I went in without knowing much but finished the course more knowledgeable. I learnt a lot of things." Pheladi from South Africa&nbsp;&nbsp;WHAT YOU WILL LEARN&bull; How to use SOCIAL MEDIA to FOLLOW breaking news and to FIND STORIES as well as sources.&nbsp;&bull; How to use ADVANCED SEARCH TECHNIQUES as a tool for finding information and locating experts.&bull; How to use social media to verify if a BREAKING NEWS story is true.&bull; How to establish the ORIGIN OF PHOTOGRAPHS and how to verify them.&nbsp;MEET YOUR INSTRUCTORS&nbsp;SUE LLEWELLYN is your course instructor. For the past 10 years, Sue has worked as a trainer for thousands of journalists, teaching them how to use social media. Before that, she was a journalist for 15 years in the BBC Newsroom.&nbsp;&emsp;&nbsp;Helping Sue is a team of experts (from left to right):
查看完整描述

1 回答

?
胡子哥哥

TA贡献1825条经验 获得超6个赞

使用此正则表达式解决它:

description.replace(/(<!--.*?-->)|(<!--[\w\W\n\s]+?-->)|<\/?[^>]+(>|$)/g, '');


查看完整回答
反对 回复 2022-01-07
  • 1 回答
  • 0 关注
  • 343 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号