jQuery addClass似乎无法在Internet Explorer中运行
我整个下午都试图弄清楚这一点,没有运气。 在我正在工作的这个网站上( http://chezkoop.ca/united )我们有几个区域(主页第一和第二列以及事件页面),它们使用了css伪选择器:nth-child()
来颜色各种颜色行。
显然, nth-child()
在Internet Explorer 8中没有工作(还没有看过IE9)所以我想用jQuery使用以下内容复制这个function(这是在$(document).ready(function(){
… });
):
$( “后:第n个孩子(甚至) ”)addClass(“ latestpost偶”)。 $(“。dbem_events_list li:nth-child(2n-1)”)。addClass(“events-odd-row”); $( “TR:第n个孩子(2N + 1)”)addClass( “日历奇数行”)。 $( “TR:第n个孩子(1)”)。addClass( “日历第一行”);
然后我在我的CSS中定义了这些类(这是第一个例子):
.post:nth-child(偶数),。кstpost-even { background-color:#f5f4e8; }
如果我使用Firebug检查Firefox中的DOM,这些类已经正确应用(尽管不必要,因为我在Firefox中)。 在Internet Explorer 8或7中查看页面时,行未着色(因此可能未应用类)。
一整个下午都试图弄清楚这一点没有运气。 我已经通过互联网进行了搜索,并没有想出任何东西。 如果有人对此有任何见解,这将是太棒了。
谢谢
阿德里安
代替 :
.post:nth-child(even), .latestpost-even { background-color: #f5f4e8; }
尝试
.post:nth-child(even) {background-color: #f5f4e8;} .latestpost-even {background-color: #f5f4e8;}
IE也有一些不明显的错误,它不会理解,如果它有一个它不理解的选择器,它会忽略整个规则集
我可以在IE的开发者工具中看到,在IE7和IE8兼容模式下都添加了类。
也许IE忽略了它不理解的那条线,所以你可以尝试:
.post:nth-child(even) { background-color: #f5f4e8; } .latestpost-even { background-color: #f5f4e8; }
或者,甚至更好:
.latestpost-even, .post:nth-child(even) { background-color: #f5f4e8; }
编辑:顺便说一下,我看着.events-odd-row
而不是.latestpost-even
但是同样的原则适用。
你有没有尝试过
$(".post:even")
要么
$(".post").even()
(后者需要扩展代码 – 请参阅api评论……)
使用Internet Explorer 7,我遇到了使用jQuery剥离表的麻烦:odd&:even addClass。 此外,需要更改所选行的背景颜色。
它会将类添加到行中(使用动态DOM的检查器PageSpy进行检查)但效果不会被看到。
我需要为行中的每个单元格添加相同的类才能使其工作。
发现了jQuery和自己。
CSS
.odd{background-color:#fafafa;} .even{background-color:#f4f4f4;} .selected_row{background-color:#ff9999;}
使用Javascript
$('tbody#interest_list_body tr:odd').find('td').andSelf().addClass('odd'); $('tbody#interest_list_body tr:even').find('td').andSelf().addClass('even');
对于选定的行,我使用了切换方法:
$('tbody#interest_list_body tr').toggle( function(){ $('tbody#interest_list_body tr').find('td').andSelf().removeClass('selected_row'); if($(this).attr('id')){ $(this).find('td').andSelf().addClass('selected_row'); } // end if }, // end fn function(){ $(this).find('td').andSelf().removeClass('selected_row'); } // end fn );
希望这有助于某人