前端使用JS从HTML中提取文本
function extractContent(html) {
return new DOMParser()
.parseFromString(html, "text/html")
.documentElement.textContent;
}
使用示例
let result = extractContent('<p>Hello World</p>')
console.log(result) // 'Hello World'

浙公网安备 33010602011771号