gpt4 book ai didi

javascript - ShadowRoot 返回为 Null - ShadowRoot 显示为打开

转载 作者:行者123 更新时间:2023-11-30 20:11:00 30 4
gpt4 key购买 nike

我正在尝试在 Javascript 中选择 Shadow 根,以便我可以设置内部元素的样式。但是当使用 elem.shadowRoot 时它返回 Null 尽管 ShadowRoot 是下一个元素。下面贴上我的调试和结果图片

这是我第一次使用 shadowRoot,所以我可能遗漏了一些明显的东西。

console.log("target");
console.log(target);

console.log("target.firstChild");
console.log(target.firstChild);

console.log("target.shadowroot");
console.log(target.shadowRoot);

console.log("target.firstChild.shadowroot");
console.log(target.firstChild.shadowRoot);

console.log("ha-card");
console.log(target.querySelector("ha-card"));

Results of Debugging

最佳答案

代码示例是针对 target.shadowroot 而不是 shadowroot 元素本身。

另请查看有关使用 firstChild 方法的文档。它可能定位不正确。

关于javascript - ShadowRoot 返回为 Null - ShadowRoot 显示为打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52417016/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com