我对 css 样式表 href 有疑问。
当我将 ref 添加为 url 时:
<link href="http://......" />
它对我的 html 没有任何影响,即使我可以在 document.styleSheets 中看到它。
当我下载 css 文件并在本地引用它时 - 它有效:
<link href="./css/test.css" />
我试过用 javascript 下载它,然后将它注入(inject)到 document.head 作为 html 元素:
var style = document.createElement("style");
style.setAttribute("type", "text/css");
style.innerHTML = response;
document.head.appendChild(style);
这也适用...
- css href 必须是一个 url,因为我需要远程更改它的能力。
- 浏览器是运行 IE 作为引擎的 Windows Phone WebView 我不明白为什么它不起作用。
最佳答案
使用此格式链接 css。
<link rel="stylesheet" type="text/css" href="/css/path" />
同时检查您的网站是否在 https 中运行。在这种情况下,出于安全考虑,浏览器将不会加载 http 资源。
关于javascript - 与 css 样式表 href 规范作斗争,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33094808/