我有一个 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/