用JS取出后台返回数据中用标签样式包裹的内容

后台返回的数据是这样的:
 `<p><span style="color: rgb(51, 51, 51); font-family: &quot;Open Sans&quot;, sans-serif;
  font-size: 12px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: 
  normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: center; text-
  indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -
  webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-
  style: initial; text-decoration-color: initial; display: inline !important; float: none;"
  >餐饮复工需要什么手续和准备工作。</span><br>
</p>`

而我只想要

餐饮复工需要什么手续和准备工作。

封装装一个字符串处理函数供自己以后使用:

const dealString = (str)=>{
     let result = "";
     let flag = false;
     for(let char of str){  
         if(char===">"){
             flag = true;
         }
         if(char==="<"){
             flag = false
         }
         if(flag&&char!==">"){
             result=result+char;
         }
     }
     return result;
}

let str = `<p><span style="color: rgb(51, 51, 51); font-family: &quot;Open Sans&quot;, sans-serif; font-size: 12px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: center; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;">餐饮复工需要什么手续和准备工作。</span><br>
</p>`

console.log(dealString(str));//餐饮复工需要什么手续和准备工作。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

前端小端长

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值