innerText 不保留换行符
innerText not preserving line breaks
我正在尝试从字符串中删除 HTML 标记,但我想删除换行符。下面的代码不起作用,到目前为止,我还没有找到有效的正则表达式解决方案。
let input = "First<br>Second"
let cleaned = document.createElement("pre");
cleaned.innerHTML = input;
let output = cleaned.innerText;
console.log(output);
我想要的:"First\nSecond"
什么returns:"FirstSecond"
我该如何解决这个问题?
你说你没有任何正则表达式可以工作,你试过了吗?
cleaned.innerHTML = input.replace(/<br>/gi, "\n");
这行得通吗?
let input = "First<br>Second"
let output = input.replace("<br>", "\n");
console.log(output);
我正在尝试从字符串中删除 HTML 标记,但我想删除换行符。下面的代码不起作用,到目前为止,我还没有找到有效的正则表达式解决方案。
let input = "First<br>Second"
let cleaned = document.createElement("pre");
cleaned.innerHTML = input;
let output = cleaned.innerText;
console.log(output);
我想要的:"First\nSecond"
什么returns:"FirstSecond"
我该如何解决这个问题?
你说你没有任何正则表达式可以工作,你试过了吗?
cleaned.innerHTML = input.replace(/<br>/gi, "\n");
这行得通吗?
let input = "First<br>Second"
let output = input.replace("<br>", "\n");
console.log(output);