[英]how to remove inline css from string in javascript
我想從 javascript 中的字符串中刪除內聯 css:
var str = "p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'}
span.Apple-tab-span {white-space:pre} This is sample text";
我想要
str = "This is sample text";
你能幫我怎么做嗎?
謝謝
如果您的字符串始終具有此模式:css 定義后的文本,您可以嘗試以下操作:
const str = "p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'} span.Apple-tab-span {white-space:pre} This is sample text"
const lastOccurrence = str.lastIndexOf('}')
console.log(str.substr(lastOccurrence+1, str.length))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.