0
在一個空Asp.Net的項目,我有以下代碼:IE TextRange.HtmlText返回意外換行符
我使用TextRange.HtmlText在IE 8來檢索DIV元素用戶的文本選擇。但是,由於某些原因,即使原始文本中沒有換行符,選定的html也包含\ r \ n。有誰知道爲什麼會發生這種情況?
如果我使用text屬性代替,則不會出現相同的行爲。
<script type="text/javascript">
function OkClick() {
var TextRange = document.selection.createRange();
var SelectedText = TextRange.htmlText;
}
</script>
<div>
This is a test with a long line of text on a single line with no line breaks.Why is there a line break returned from htmlText on the TextRange object
</div>
<button onclick="OkClick()">OK</button>
分配給我的SelectedText變量如下:正如你可以看到有字後換行「爲什麼」
This is a test with a long line of text on a single line with no line breaks.Why \r\nis there a line break returned from htmlText on the TextRange object
我知道,但我想弄清楚問題的根源是什麼 – TGH 2013-03-18 21:02:54