slot
特性为
元素
interface returns the name of the shadow DOM slot the element is inserted in.
A slot is a placeholder inside a web component that users can fill with their own markup (see Using templates and slots 了解更多信息)。
var aString = element.slot element.slot = aString
A
DOMString
.
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 slotable 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 name of the corresponding
<slot>
元素。
let slottedSpan = document.querySelector('my-paragraph span')
console.log(slottedSpan.slot); // logs
| 规范 | 状态 | 注释 |
|---|---|---|
|
DOM
The definition of 'slot' in that specification. |
实时标准 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
slot
|
Chrome 53 | Edge ≤79 | Firefox 63 | IE ? | Opera Yes | Safari 10 | WebView Android 53 | Chrome Android 53 | Firefox Android 63 | Opera Android Yes | Safari iOS Yes | Samsung Internet Android 6.0 |
完整支持
兼容性未知
元素
accessKey
属性
childElementCount
children
classList
className
clientHeight
clientLeft
clientTop
clientWidth
currentStyle
firstElementChild
id
innerHTML
lastElementChild
localName
名称
namespaceURI
nextElementSibling
onfullscreenchange
onfullscreenerror
openOrClosedShadowRoot
outerHTML
part
prefix
previousElementSibling
runtimeStyle
scrollHeight
scrollLeft
scrollLeftMax
scrollTop
scrollTopMax
scrollWidth
shadowRoot
slot
tabStop
tagName
after()
animate()
append()
attachShadow()
before()
closest()
computedStyleMap()
createShadowRoot()
getAnimations()
getAttribute()
getAttributeNames()
getAttributeNode()
getAttributeNodeNS()
getAttributeNS()
getBoundingClientRect()
getClientRects()
getElementsByClassName()
getElementsByTagName()
getElementsByTagNameNS()
hasAttribute()
hasAttributeNS()
hasAttributes()
hasPointerCapture()
insertAdjacentElement()
insertAdjacentHTML()
insertAdjacentText()
matches()
msZoomTo()
prepend()
querySelector()
querySelector()
querySelectorAll()
querySelectorAll()
releasePointerCapture()
remove()
removeAttribute()
removeAttributeNode()
removeAttributeNS()
replaceChildren()
replaceWith()
requestFullscreen()
requestPointerLock()
scroll()
scrollBy()
scrollIntoView()
scrollIntoViewIfNeeded()
scrollTo()
setAttribute()
setAttributeNode()
setAttributeNodeNS()
setAttributeNS()
setCapture()
setPointerCapture()
toggleAttribute()
afterscriptexecute
auxclick
blur
click
compositionend
compositionstart
compositionupdate
contextmenu
copy
cut
dblclick
DOMActivate
DOMMouseScroll
error
focus
focusin
focusout
fullscreenchange
fullscreenerror
gesturechange
gestureend
gesturestart
keydown
keypress
keyup
mousedown
mouseenter
mouseleave
mousemove
mouseout
mouseover
mouseup
mousewheel
MozMousePixelScroll
msContentZoom
MSGestureChange
MSGestureEnd
MSGestureHold
MSGestureStart
MSGestureTap
MSInertiaStart
MSManipulationStateChanged
overflow
paste
scroll
select
show
touchcancel
touchend
touchmove
touchstart
underflow
webkitmouseforcechanged
webkitmouseforcedown
webkitmouseforceup
webkitmouseforcewillbegin
wheel