Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/428.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何移动多个<;风格>;节点内容到单个<;风格>;高效节点_Javascript_Html_Css_Dom - Fatal编程技术网

Javascript 如何移动多个<;风格>;节点内容到单个<;风格>;高效节点

Javascript 如何移动多个<;风格>;节点内容到单个<;风格>;高效节点,javascript,html,css,dom,Javascript,Html,Css,Dom,我在文档中有几个带有css的标记,我想收集它们的css并将其移动到单个 我现在正在做这个 const collectedCss = Array.from(document.querySelectorAll("[data-ssr-styles='chunk']")) .reduce((acc, curr) => [...acc, curr.innerHTML], []) .join(''); document.querySelector("[da

我在文档中有几个带有css的
标记,我想收集它们的css并将其移动到单个

我现在正在做这个

const collectedCss = Array.from(document.querySelectorAll("[data-ssr-styles='chunk']"))
    .reduce((acc, curr) => [...acc, curr.innerHTML], [])
    .join('');
document.querySelector("[data-ssr-styles='head']").appendChild(document.createTextNode(collectedCss));
我想通过
innerHtml
/
innerText
获取样式并不是处理样式的方式-将样式从一个节点移动到另一个节点的正确/有效方式是什么?我应该迭代文本节点并将它们附加到主样式吗

const collectedCss=Array.from(
document.querySelectorAll(“[datassr styles='chunk']”)
)
.reduce((acc,curr)=>[…acc,curr.innerHTML],)
.加入(“”);
文件
.querySelector(“[data ssr styles='head']”)
.appendChild(document.createTextNode(collectedCss))

身体{
背景:红色;
}
身体{
背景:蓝色;
}
身体{
背景:绿色;
}

你为什么投票赞成结束而不发表评论?我在评论中尽可能准确地描述了需要澄清的内容。甚至还有一个片段