弃用
This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the 兼容性表格 at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

HTML <content> element —an obsolete part of the Web 组件 suite of technologies—was used inside of Shadow DOM as an insertion point , and wasn't meant to be used in ordinary HTML. It has now been replaced by the <slot> element, which creates a point in the DOM at which a shadow DOM can be inserted.

注意: Though present in early draft of the specifications and implemented in several browsers, this element has been removed in later versions of the spec, and should not be used. It is documented here to assist in adapting code written during the time it was included in the spec to work with newer versions of the specification.

内容类别 Transparent content .
准许内容 流内容 .
Tag omission None, both the starting and ending tag are mandatory.
Permitted parent elements Any element that accepts flow content.
DOM 接口 HTMLContentElement

属性

此元素包括 全局属性 .

select
A comma-separated list of selectors. These have the same syntax as CSS selectors. They select the content to insert in place of the <content> 元素。

范例

Here is a simple example of using the <content> element. It is an HTML file with everything needed in it.

注意: For this code to work, the browser you display it in must support Web Components. See Enabling Web Components in Firefox .

<html>
  <head></head>
  <body>
  <!-- The original content accessed by <content> -->
  <div>
    <h4>My Content Heading</h4>
    <p>My content text</p>
  </div>
  <script>
  // Get the <div> above.
  var myContent = document.querySelector('div');
  // Create a shadow DOM on the <div>
  var shadowroot = myContent.createShadowRoot();
  // Insert into the shadow DOM a new heading and
  // part of the original content: the <p> tag.
  shadowroot.innerHTML =
   '<h2>Inserted Heading</h2> <content select="p"></content>';
  </script>
  </body>
</html>
					

If you display this in a web browser it should look like the following.

content example

规范

This element is no longer defined by any specifications.

浏览器兼容性

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
content 弃用 非标 Chrome 完整支持 35 Edge 完整支持 79 Firefox 不支持 33 — 59 Disabled
不支持 33 — 59 Disabled
Disabled ). To change preferences in Firefox, visit
IE 不支持 No Opera 完整支持 26 Safari 不支持 No WebView Android 完整支持 37 Chrome Android 完整支持 37 Firefox Android 不支持 33 — 59 Disabled
不支持 33 — 59 Disabled
Disabled ). To change preferences in Firefox, visit
Opera Android ? Safari iOS 不支持 No Samsung Internet Android 完整支持 3.0

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

非标。预期跨浏览器支持较差。

非标。预期跨浏览器支持较差。

弃用。不要用于新网站。

弃用。不要用于新网站。

用户必须明确启用此特征。

用户必须明确启用此特征。

另请参阅

元数据

  • 最后修改: