什么元素是可插入的?

时间:2018-04-21 08:20:21

标签: html shadow-dom custom-element slot native-web-component

我可以使用tr(表格行)作为命名插槽吗? 当我使用tr作为插槽的后备内容时会发生什么?

像这样:

<x-table>
    <tr slot="x-row">
        <td>data</td>
        <td>data</td>
    </tr>
</x-table>

codepen https://codepen.io/JJia/pen/odXrWJ

中的示例代码

1 个答案:

答案 0 :(得分:1)

<tr>元素必须包含parent among <thead>, <tbody>, <tfoot> or <table>个元素。

不幸的是,这些元素不能支持Shadow DOM。请参阅elements with the attachShadow() method列表。

因此,他们的第一级孩子(即<tr>)不能与slot属性一起使用。