概述
HTMLElement.contentEditable
属性用于表明元素是否是可编辑的。该枚举属性(enumerated attribute)可以具有下面的几种值之一:
"true"
表明该元素可编辑。"false"
表明该元素不可编辑。"inherit"
表明该元素继承了其父元素的可编辑状态。
语法
editable = element.contentEditable element.contentEditable = "true"
规范
Specification | Status | Comment |
---|---|---|
WHATWG HTML Living Standard contenteditable |
Living Standard | |
浏览器兼容性
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 11 | 3.0 (1.9) | 6 | 10.6 | 3.2 |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | 3 | 1.0 (1.9) | 6 | 未实现 | 5 |
Bugs
- IE bug 796187: IE10 crashes in some cases when editing lists
- IE bug 858749: IE11+ uses invalid positioning for caret when an element is floated
- IE bug 809254: IE9-10 window freezes when using mousewheel while dragging
- IE bug 794285: IE10-11 does not fire the
input
event - IE bug 801770: IE10 crashes after selecting "Cut" from the context menu
- IE bug 807199: IE11+ does not allow placing the caret in an empty table cell
- IE bug 774350: IE10 does not fire
contextmenu
event when right-clicking on misspelled words - IE bug 864804: IE11 appends
<br>
elements to<body>
when showing/hiding an<iframe>
with contenteditable document inside - IE bug 907422: IE11 does not allow disabling resize handles for images/inputs
相关链接
HTMLElement.isContentEditable
- 全局属性 contenteditable
- Why ContentEditable is Terrible, Or: How the Medium Editor Works