gpt4 book ai didi

javascript - 使用范围保留选择中的换行符和回车符? javascript/jquery

转载 作者:行者123 更新时间:2023-11-28 10:14:46 25 4
gpt4 key购买 nike

我有以下代码

if(this.window.getSelection) {
var range = this.range;
var contents = range.extractContents();
console.log(contents);
return contents.textContent;
}

contents 给了我一个文档片段。当我检查该片段的文本内容时,它会将我选择的换行符折叠成单个字符串。

如何保留字符串的格式?

最佳答案

如果您的 contents 是 html 元素,则可以使用 contents.innerHTML ,如果它是 jQuery 对象,则可以使用 contents.html() .

ps:this.window.getSelection不应该是this.window.getSelection()吗?

关于javascript - 使用范围保留选择中的换行符和回车符? javascript/jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6820671/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com