HTMLElement.contentEditable

概述

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

  • "true" 表明该元素可编辑。
  • "false" 表明该元素不可编辑。
  • "inherit" 表明该元素继承了其父元素的可编辑状态。

语法

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

规范

Specification Status Comment
HTML Living Standard
contenteditable
Living Standard  
 

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
contentEditableChrome Full support 1Edge Full support 12Firefox Full support 3IE Full support 8Opera Full support 9Safari Full support 6WebView Android Full support 4.4Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support 1.0

Legend

Full support  
Full support

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

相关链接