我不確定是否可以用純 js 做
我正在嘗試將一些樣式添加到從 css 檔案加載的樣式標簽中,
我的問題是,我不知道如何讀取檔案以轉換為字串
我找不到解決方案來做類似的事情
import baseStyle from "./css/style.css"
//or
const baseStyle require("./css/style.css")
所以這個想法是在html中決議
const cssStyle = document.createElement("style");
cssStyle.innerHTML = baseStyle;
const doc = iframe.contentDocument;
doc.head.appendChild(cssStyle)
我正在使用 GrapesJs,我正在嘗試從框架中決議一些 css
謝謝您的幫助
我嘗試從多種方式加載css,但沒有任何效果
uj5u.com熱心網友回復:
您可以嘗試使用fetch將檔案作為文本獲取。
像這樣的東西:
async function setCss() {
const baseStyle = await fetch("./css/style.css").then(res => res.text())
const cssStyle = document.createElement("style");
cssStyle.innerHTML = baseStyle;
const doc = iframe.contentDocument;
doc.head.appendChild(cssStyle)
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/526148.html
上一篇:將工具提示與相對父級對齊
