jQuery addClass似乎在Internet Explorer中不工作 [英] jQuery addClass appears not to be working in Internet Explorer

查看:553
本文介绍了jQuery addClass似乎在Internet Explorer中不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力想出这一点,下午没有运气。在这个网站上,我正在努力( http://chezkoop.ca/united ),我们有几个领域首页第一列和第二列以及事件页),它们使用css伪选择器:nth-​​child()来对各行进行着色。

I have been trying to figure this out all afternoon with no luck. On this site I am working on (http://chezkoop.ca/united) we have a couple of areas (homepage columns one and two and the events page) which utilize the css pseudo selector :nth-child() to colour various rows.

显然, nth-child()在Internet Explorer 8和下来不工作(还没有看过IE9 ...)所以我想使用jQuery使用以下代码复制此功能(这是放在 $(document).ready(function(){ ... }) / code>):

Obviously, nth-child() does not work in Internet Explorer 8 and down (haven't looked at IE9 yet...) so I want to replicate this functionality with jQuery using the following (this being place inside $(document).ready(function(){ ... });):


$(".post:nth-child(even)").addClass("latestpost-even");
$(".dbem_events_list li:nth-child(2n-1)").addClass("events-odd-row");
$("tr:nth-child(2n+1)").addClass("calendar-odd-row");
$("tr:nth-child(1)").addClass("calendar-first-row");

然后我在CSS中定义了这些类(这是第一个例子):

I have then defined those classes in my CSS like this (this is the first example only):


.post:nth-child(even), .latestpost-even {
background-color: #f5f4e8;
}

如果我在Firefox中使用Firebug检查DOM,这些类已经正确应用(尽管不必要,在Firefox中)。当在Internet Explorer 8或7中查看页面时,行不是彩色的(因此可能没有应用这些类)。

If I check the DOM in Firefox with Firebug these classes have been applied correctly (although unnecessarily, because I'm in Firefox). When viewing the page in Internet Explorer 8 or 7, the rows are not coloured (so presumably the classes are not being applied).

没有运气。我已经通过interwebs搜索,没有提出任何东西。如果任何人有任何洞察这将是太棒了。

Been trying to figure this out all afternoon with no luck. I've had a search through the interwebs and haven't come up with anything. If anyone has any insight into this that would be fantastic.

感谢

Adrian

推荐答案

而不是:

.post:nth-child(even), .latestpost-even {
   background-color: #f5f4e8;
}

尝试

.post:nth-child(even) {background-color: #f5f4e8;}

.latestpost-even {background-color: #f5f4e8;}

IE也有一些不可思议的伪装,它不明白,因为它会忽略整个规则集如果它有一个选择器它不明白

IE also has a little foible with those pseudos that it doesn't understand in that it will ignore the whole ruleset if it has a selector it doesn't understand

这篇关于jQuery addClass似乎在Internet Explorer中不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆