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

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

  • true 或空字符串,表示元素是可编辑的;
  • false 表示元素不是可编辑的。

如果没有设置该属性,其默认值继承自父元素。

该属性是一个枚举属性,而非布尔属性。这意味着必须显式设置其值为 truefalse 或空字符串中的一个,并且不允许简写为 <label contenteditable>Example Label</label>正确的用法是 <label contenteditable="true">Example Label</label>

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

规范

规范版本 规范状态 注解
HTML Living Standard
contenteditable
Living Standard No change from latest snapshot, HTML 5.1
HTML 5.1
contenteditable
Recommendation Snapshot of HTML Living Standard, no change from HTML5
HTML5
contenteditable
Recommendation Snapshot of  HTML Living Standard, initial definition.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
contenteditableChrome Full support YesEdge Full support YesFirefox Full support 3IE Full support 5.5Opera Full support 9Safari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?
contenteditable="caret"
Experimental
Chrome Full support YesEdge ? Firefox No support NoIE No support NoOpera Full support YesSafari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android No support NoOpera Android ? Safari iOS ? Samsung Internet Android ?
contenteditable="events"
Experimental
Chrome Full support YesEdge ? Firefox No support NoIE No support NoOpera Full support YesSafari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android No support NoOpera Android ? Safari iOS ? Samsung Internet Android ?
contenteditable="plaintext-only"
Experimental
Chrome Full support YesEdge ? Firefox No support NoIE No support NoOpera Full support YesSafari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android No support NoOpera Android ? Safari iOS ? Samsung Internet Android ?
contenteditable="typing"
Experimental
Chrome Full support YesEdge ? Firefox No support NoIE No support NoOpera Full support YesSafari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android No support NoOpera Android ? Safari iOS ? Samsung Internet Android ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.

相关链接

文档标签和贡献者

此页面的贡献者: mdnwebdocs-bot, zhangchen, xgqfrms, eforegist, AlexChao
最后编辑者: mdnwebdocs-bot,