javascript - ShadowRoot 以 Null 形式返回 - ShadowRoot 显示为打开
问题描述
我正在尝试在 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"));
解决方案
代码示例是定位,target.shadowroot
而不是 shadowroot 元素本身。
另请查看使用 firstChild 方法的文档。它可能定位不正确。
推荐阅读
- c# - 使用 ASP.NET Core 2.2 “找不到任何兼容的框架版本”
- excel - 向 Array 元素添加过滤
- linux - 在ubuntu中查找一个守护进程的包名和服务名
- c++ - 在 pybind11 和 C++ 中添加源时没有给目标错误提供源
- browser - 基于图像的 WebAR 浏览器框架?
- spring-boot - 为配置文件禁用 JMS
- javascript - 在首次渲染期间处理组件中的未定义/空属性
- python - 如何在列表中附加嵌套的元组项?
- ruby-on-rails - 尝试在 Rails 中获取登录/退出和帐户图标时出现错误,我该如何解决?
- odbc - 是否可以从 SSMS 查询 SAS 表?