简体   繁体   English

保留Shadow Dom主机内容

[英]Preserving Shadow Dom host content

I am creating a ShadowDom on a DOM element/host. 我正在DOM元素/主机上创建ShadowDom。 I can preserve, still be visible, the respective host childElements by using the select attribute, however the text childNode that is inside the host is not selected and there for remains invisible. 通过使用select属性,我可以保留各个主机childElement,但仍然可见,但是主机内部的文本childNode未被选中,并且在那里仍然不可见。

Can you preserve the content of a ShadowDom host besides using the select attribute on childElements? 除了在childElements上使用select属性之外,您还可以保留ShadowDom主机的内容吗?

Here is my code: 这是我的代码:

<div id="element">
      <div class="first">This will be displayed</div>
      This text node will be not displayed...and I want to
</div>

<template id="template">

      <div style="color: red;">
        <content select=".first"></content>
      </div>

</template>

http://jsfiddle.net/JgfKz/2/ http://jsfiddle.net/JgfKz/2/

I got it. 我知道了。 If anyone needs this: 如果有人需要此:

var element = document.querySelector('#element');
var root1 = element.webkitCreateShadowRoot();
root1.innerHTML = '<div>Root extra ShadowDom content</div><content></content>';

Much simpler then I thought: http://jsfiddle.net/JgfKz/4/ 比我想的要简单得多: http : //jsfiddle.net/JgfKz/4/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM