@import url() 的 jquery 选择

标签 jquery css refresh

https://github.com/NV/auto_update_stylesheets

我正在尝试更新这个很棒的脚本以处理残酷的 css 导入,例如:

<style type="text/css" media="all">@import url("http://192.168.1.238/system.base.css");
</style>

该脚本仅适用于 css 的正常包含,例如:

<link href="stylesheets/bundle_github.css" media="screen" rel="stylesheet" type="text/css" />

我理解这个脚本的逻辑,但我的问题是如何选择 @import url ('foo')url() 中的部分,这个示例 foo。如果我知道这是否可行,我就可以解决我的问题。

谢谢。

最佳答案

确实没有一种好的跨浏览器方法可以做到这一点。参见 QuirksMode有关浏览器实现 CSS 规则的方式的详细信息。

您必须确定获取 @import 规则的正确方法才能解析它。

对于 IE,您需要获取 document.styleSheets[0].imports[0] 假设第一个 stylelink rel="stylesheet " 页面上的引用包含 @import 规则作为其第一条规则。看起来你需要调用 document.styleSheets[0].removeImport(0);document.styleSheets[0].addImport("URL"); 来修改。

其他浏览器似乎使用 document.styleSheets[0].cssRules[0] 假设相同的结构。对于那些你需要使用 document.styleSheets[0].deleteRule(0)document.styleSheets[0].insertRule('@import url("URL")') 。这些是标准的 DOM Level 2 规则;见here .

希望对您有所帮助。

关于@import url() 的 jquery 选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6192717/

相关文章:

css - 为什么我的 CSS 属性被覆盖/忽略?

visual-studio-2010 - Visual Studio 2010 - 在运行 Win7/Bootcamp 的 MacPro 上显示更新非常慢

vba - MS Excel - 如何每 5 秒自动刷新一次单元格?

html - 使两个搜索字段填充 100% 宽度

javascript - animate() 在 Internet Explorer 中不工作

c++ - 除非隐藏 CFrameWnd,否则文件对话框不会刷新

javascript - 带有隐藏/显示的 jquery 屏幕

javascript - 在输入元素中隐藏文本

javascript - 从 ContactsApp Service 获取联系人以使用 GAS 自动完成

javascript - Tablesorter 对点击外部链接进行排序