弃用
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
<shadow>
element
—an obsolete part of the
Web 组件
technology suite—was intended to be used as a shadow DOM
insertion point
.
You might have used it if you have created multiple shadow roots under a shadow host. It is not useful in ordinary HTML.
| 内容类别 | Transparent content |
|---|---|
| 准许内容 | 流内容 |
| Tag omission | None, both the starting and ending tag are mandatory. |
| Permitted parents | Any element that accepts flow content. |
| Permitted ARIA roles | None |
| DOM 接口 |
HTMLShadowElement
|
此元素包括 全局属性 .
Here is a simple example of using the
<shadow>
element. It is an HTML file with everything needed in it.
注意: This is an experimental technology. 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>
<!-- This <div> will hold the shadow roots. -->
<div>
<!-- This heading will not be displayed -->
<h4>My Original Heading</h4>
</div>
<script>
// Get the <div> above with its content
var origContent = document.querySelector('div');
// Create the first shadow root
var shadowroot1 = origContent.createShadowRoot();
// Create the second shadow root
var shadowroot2 = origContent.createShadowRoot();
// Insert something into the older shadow root
shadowroot1.innerHTML =
'<p>Older shadow root inserted by
<shadow></p>';
// Insert into younger shadow root, including <shadow>.
// The previous markup will not be displayed unless
// <shadow> is used below.
shadowroot2.innerHTML =
'<shadow></shadow> <p>Younger shadow
root, displayed because it is the youngest.</p>';
</script>
</body>
</html>
If you display this in a web browser it should look like the following.
This element is no longer defined by any specifications.
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
shadow
弃用
非标
|
Chrome 完整支持 35 | Edge 完整支持 79 |
Firefox
不支持
33 — 59
Disabled
|
IE 不支持 No | Opera 完整支持 26 | Safari 不支持 No | WebView Android 完整支持 37 | Chrome Android 完整支持 37 |
Firefox Android
不支持
33 — 58
Disabled
|
Opera Android ? | Safari iOS 不支持 No | Samsung Internet Android 完整支持 3.0 |
完整支持
不支持
兼容性未知
非标。预期跨浏览器支持较差。
弃用。不要用于新网站。
用户必须明确启用此特征。
<content>
,
<slot>
,
<template>
,
<element>
<content>
<shadow>
<slot>
<template>