开发者

How to get value from contentEditable div in IE

I'm trying to create a very simple contentEditable div input. However, any way that I can think of to get the value of the input is not exactly what the user typed in IE because whitespace is collapsed. i.e. "hello world" becomes "hello world". But it's important to me that I be able to get the text as the user has type开发者_JAVA百科d it if at all possible. Any ideas how I can do this?


Did you try to read the innerHTML from the div?


It turns out that I can get the value just fine using innerHTML without IE collapsing any spaces. However, there is no way to set the value such that IE doesn't collapse spaces, which makes it absolutely impossible to unit test.


Use the good old " " and it will work as you want ;)


For your example did you try innerText, I'm just afraid that using innerHTML might return some added markup that some browsers might add when manipulating the editable content.

Check this stackoverflow questions for difference between innerHTML and innerText:

Difference between innerText and html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜