HTMLElement.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.

概述

HTMLElement.contentEditable 属性用于表明元素是否是可编辑的。该枚举属性(enumerated attribute)可以具有下面的几种值之一:

  • "true" 表明该元素可编辑。
  • "false" 表明该元素不可编辑。
  • "plaintext-only" 表明该元素可以纯文本格式编辑,富文本格式会被禁用。
  • "inherit" 表明该元素继承了其父元素的可编辑状态。

语法

editable = element.contentEditable
element.contentEditable = "true"

规范

Specification
HTML
# 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
plaintext-only as a value

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.

在 IE 浏览器中,contenteditable 不能直接用在 <table><col><colgroup><tbody><td><tfoot><th><thead><tr> 标签上。一个可编辑的 <span> 或者 <div> 标签可以放在表格单元格内部。

相关链接