contenteditable

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

* Some parts of this feature may have varying levels of support.

全局属性 contenteditable 是一个枚举属性,表示元素是否可被用户编辑。如果可以,浏览器会修改元素的组件以允许编辑。

尝试一下

该属性必须是下面的值之一:

  • true空字符串,表示元素是可编辑的。
  • false 表示元素不是可编辑的。
  • plaintext-only 表示元素的原始文本是可编辑的,但富文本格式会被禁用。

如果没有设置该属性的值(例如:<label contenteditable>Example Label</label>),则其值被视为空字符串。

如果没给出该属性或设置了无效的属性值,则其默认值继承自父元素:即,如果父元素可编辑,该子元素也可编辑。

注意,虽然该属性允许设定的值包括 truefalse,但该属性仍是一个枚举属性而非布尔属性。

你可以使用 CSS caret-color 属性设置用于绘制文本插入 caret 的颜色。

规范

Specification
HTML
# attr-contenteditable

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
contenteditable
contenteditable="plaintext-only"

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
In development. Supported in a pre-release version.
In development. Supported in a pre-release version.

参见