[英]Preserving newlines and carriage returns from a selection using range? javascript / jquery
我有以下代碼
if(this.window.getSelection) {
var range = this.range;
var contents = range.extractContents();
console.log(contents);
return contents.textContent;
}
內容給了我一個文檔片段。 當我檢查該片段的文本內容時,它會將我選擇的換行符折疊成一個字符串。
如何保留字符串的格式?
如果您的contents
是html元素,則可以使用contents.innerHTML
如果它是jQuery對象,則可以使用contents.innerHTML
contents.html()
。
ps: this.window.getSelection
不應該是this.window.getSelection()
嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.