assignedSlot
只读特性在
Slottable
interface returns an
HTMLSlotElement
表示
<slot>
element the node is inserted in.
var slotElement = elementInstance.assignedSlot
HTMLSlotElement
实例,或
null
if the element is not assigned to a slot, or if the associated shadow root was attached with its
mode
设为
closed
(见
Element.attachShadow
for further details).
In our
simple-template example
(
see it live
), we create a trivial custom element example called
<my-paragraph>
in which a shadow root is attached and then populated using the contents of a template that contains a slot named
my-text
.
当
<my-paragraph>
is used in the document, the slot is populated by a slottable element by including it inside the element with a
slot
attribute with the value
my-text
. Here is one such example:
<my-paragraph> <span slot="my-text">Let's have some different text!</span> </my-paragraph>
In our JavaScript file we get a reference to the
<span>
shown above, then log a reference to the original
<slot>
element the
<span>
was inserted in.
let slottedSpan = document.querySelector('my-paragraph span')
console.log(slottedSpan.assignedSlot); // logs '
| 规范 | 状态 | 注释 |
|---|---|---|
|
DOM
The definition of 'assignedSlot' in that specification. |
实时标准 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
assignedSlot
|
Chrome 53 | Edge 79 |
Firefox
63
|
IE No | Opera 40 | Safari 10.1 | WebView Android 53 | Chrome Android 53 |
Firefox Android
63
|
Opera Android 41 | Safari iOS 10.3 | Samsung Internet Android 6.0 |
完整支持
不支持
实验。期望将来行为有所改变。
用户必须明确启用此特征。
Slottable
Slottable: assignedSlot