让我们阅读一个令人满意的元素:
<span id="myinput" contenteditable="true">This is editable.<br>Yes it is.</span>
刚刚在文本末尾手动添加了两个空格。
我明白了:
textContent
=&gt; "This is editable.Yes it is. "
innerText
=&gt; undefined
innerHTML
=&gt; "This is editable.<br>Yes it is. "
jQuery .text()
=&gt;与textContent
相同,即换行丢失
如何获得"This is editable.\n Yes it is. "
?(当然一些正则表达式可以在innerHTML上运行,但那很脏:也许有很多东西我应该解析......)