jquery - 在 IE 中使用 jQuery 从 CSS 获取系统颜色

标签 jquery css internet-explorer background-color systemcolors

我有一个 css 规则将背景颜色定义为 the window system color :

background-color: window;

当我尝试使用 jQuery 的 css 方法获取背景颜色时:$(selector).css("background-color");。它在 Google Chrome 中运行良好,它返回正确的颜色,尽管不是作为系统颜色,而是转换为 rgb(255,255,255)。在 IE9 中,它返回 rgb(-1,-1,-1)... 当然在应用时呈现黑色而不是白色。

最佳答案

可能不是您正在寻找的“答案”——但有几点要注意:

至于“为什么会这样”——参见http://msdn.microsoft.com/en-us/library/ie/aa358804(v=vs.85).aspx - 特别是:

Unlike the other named colors however, user-defined system colors have no numeric RGB equivalent because the exact color is not known until the Web page is viewed on the user's system.

另请注意:

The system color names have been deprecated in the Cascading Style Sheets, Level 3 (CSS3) recommendation.

如果绝对要求您能够在 IE 上确定用户系统颜色的 RGB 颜色代码,那么您可以求助于 https://developers.google.com/chrome/chrome-frame/弥合差距

关于jquery - 在 IE 中使用 jQuery 从 CSS 获取系统颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9941498/

相关文章:

javascript - JQuery .load() 在 Internet Explorer 中不起作用

html - 网站元素在 IE 中不起作用

jquery - jScrollPane 切断内容底部

javascript - 如何 float 不同高度的元素?

javascript - 如何在 IE 中自动允许被阻止的内容?

css - 通过了解父类来定位子 ID el

html - Chrome/Safari/WebKit(和 IE?): Overflow not being respected

javascript - jQuery remove() 或 after() 导致空格被删除

javascript - 我如何在 jQuery 中选择直系子代

javascript - 你可以在 jQuery 中使用 length() 按图像名称计算元素吗?