IE 中内联 contenteditable 元素前后的换行符
我需要制作内联元素contenteditable
.它适用于 Chrome/Firefox,但如果它是 contenteditable
,IE(至少 11 个)会在 span 前后插入换行符.
小提琴链接:
这是 IE:
有什么办法可以解决吗?
UPD:
我的IE版本:
我的小提琴页面上的 IE 模式:
另外,我使用的是 Windows 7 Professional,64 位
解决方案注意:contentEditable
在所有浏览器甚至版本中都存在极大的错误和不一致.使用 CKEditor 之类的 JS WYSIWYG 编辑器(可以内联编辑)要好得多.例如,当在 <p>
或 <div>
或 中按 Enter 时,某些浏览器会换行上一个文本块><span>
,而其他人将输入 <br>
.有时一个或两个 <br>
必须在前面或结尾.两个 <br>
算作一行......直到它没有.IE 在表格或内联元素中不支持 contentEditable
. 粘贴插入 HTML 而不是文本.问题层出不穷,会让你无休止的沮丧.
I need to make inline element contenteditable
. It works fine for Chrome/Firefox, but IE (11 at least) inserts line break before and after span if it's contenteditable
.
Link to fiddle: https://jsfiddle.net/nokpy02g/1/
This is how it looks like in Chrome:
And this is IE:
Is there is any way to fix it?
UPD:
My IE version:
IE mode on my fiddle page:
Also, I am using Windows 7 Professional, 64bit
解决方案Be aware: contentEditable
is extremely buggy and inconsistent across all browsers and even versions. You are much, much better of using a JS WYSIWYG editor like CKEditor (which can edit inline). For example, some browsers will wrap the previous block of text when pressing Enter in a <p>
or <div>
or <span>
, while others will enter <br>
. Sometimes a <br>
or two must be at the front or end. Two <br>
s count as a single line...until it doesn't. IE doesn't support contentEditable
properly in table or inline elements. Pasting inserts HTML rather than text. The problems go on and on, and will cause you endless frustration.
相关文章