:root选择器常用于定义全局的CSS变量(也称为自定义属性),这些变量可以在整个文档范围内被引用和使用。 在JavaScript中通过document.documentElement获取:root对应的元素: 在JavaScript中,:root对应的元素可以通过document.documentElement属性获取。这个属性返回文档的根元素,即<html
varcolor1=window.getComputedStyle(document.documentElement).getPropertyValue('--my-color1');variframe=document.getElementById("testIframe");iframe.contentDocument.getElementById("contentBlock").style.backgroundColor=color1; 如此,通过该段代码就可以实现将CSS Root Variable的值传给iframe并且应用到对应的组...