gpt4 book ai didi

jquery - IE8 和 jQuery 选择器

转载 作者:技术小花猫 更新时间:2023-10-29 10:29:42 24 4
gpt4 key购买 nike

今天我注意到 jQuery 选择器和 addClass() 函数的组合在 IE8 上不能正常工作。

例如,当我要确保在表格中选择偶数行时,我写道:

jQuery(document).ready(function($){
$("#table1 tr:nth-child(even)").addClass("even");
}

对于 CSS,我写道:

#table1 tr:nth-child(even), #table1 tr.even {
background-color: #ff0;
}

在 Firefox、Chrome、Safari 和 Opera 中,即使 CSS 文件中没有伪类选择器,偶数行也会被选中。然而,在IE8中,情况并非如此。这些行没有不同的背景颜色。

这很奇怪,因为当我使用时:

jQuery(document).ready(function($){
$("#table1 tr:nth-child(even)").css({"background-color":"#ff0"});
}

所选行在 IE8 中突出显示。


问题的一个例子是问题可以在这里看到 - 24ways example .在 Firefox、Chrome、Safari 和 Opera 中,奇数行被指定为“奇数”类。但是,在 IE8 中,它们没有被分配到“奇数”类,也没有突出显示。

最佳答案

选择器在 jQuery 方面可以正常工作...但是 IE8 完全放弃样式规则(符合 the specification ),因为它不识别 nth-child:

tr:nth-child(odd) td, tr.odd td {
background-color: #86B486;
}

如果你拆分它,它会正常工作:

tr:nth-child(odd) td {
background-color: #86B486;
}
tr.odd td {
background-color: #86B486;
}

Here's the original version (IE8 删除了一条规则)和 here's a fixed sample , 规则拆分。


为了完整起见,颠倒规则like this 没有帮助:

tr.odd td, tr:nth-child(odd) td {
background-color: #86B486;
}

关于jquery - IE8 和 jQuery 选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3282066/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com