javascript - 第 N 个 child 使用 Jquery 而不是 CSS

标签 javascript jquery html css

我在我的 CSS 代码中使用了 nth-child,但它在 IE 8 中不起作用。 我知道 IE 8 无法处理 nth-child 但我需要找到一种方法让它工作。

这是我的代码:

.paypalshop .shop-groups li:nth-child(1){
  float:left;
  border: 1px solid #ccc;
  width:200px;

   }

.paypalshop .shop-groups li:nth-child(2){
  float:left;
  border: 1px solid #ccc;
  width:150px;
   }

.paypalshop .shop-groups li:nth-child(3){
  float:left;
  border: 1px solid #ccc;
  width:210px;
   }

.paypalshop .shop-groups li:nth-child(4){
  float:left;
  border: 1px solid #ccc;
  width:200px;
   }

.paypalshop .shop-groups li:nth-child(5){
  float:left;
  border: 1px solid #ccc;
  width:70px;
   }

.paypalshop .shop-groups li:nth-child(6){
  float:left;
  border: 1px solid #ccc;
  width:105px;
   }

.paypalshop .shop-groups li:nth-child(7){
  float:left;
  border: 1px solid #ccc;
  width:154px;
   }

.paypalshop .shop-groups li:nth-child(8){
  float:left;
  border: 1px solid #ccc;
  width:130px;
   }   

.paypalshop .shop-groups li:nth-child(9){
  float:left;
  border: 1px solid #ccc;
  width:220px;
   }
.paypalshop .shop-groups li:nth-child(10){
  float:left;
  border: 1px solid #ccc;
  width:220px;
   }

所以我需要找到一种方法让 nth-child 函数在 IE 8 上工作。是否有任何 jQuery 方法我可以用来让它在 IE 8 上工作?

谢谢!

最佳答案

是的,使用 :nth-child 选择器

http://api.jquery.com/nth-child-selector/

随着 css 的改变

http://api.jquery.com/css/

例如

$("paypalshop .shop-groups li:nth-child(2)").css("width":"150px","float":"left","border":"1px solid #ccc");

关于javascript - 第 N 个 child 使用 Jquery 而不是 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11765722/

相关文章:

javascript - 停止 jquery 元素上的事件传播

javascript - 我可以使用 JavaScript 事件在元素之间传输数据吗?

javascript - jQuery - 鼠标输入闪烁图像

javascript - 如何在AJAX中成功执行两个功能(关闭和保存)?

javascript - 如何中止/停止正在进行的亚马逊 AWS s3 上传

javascript - jquery 在父 div 中选择类

javascript - 在 Jquery 中搜索无法显示 'data-name' 的结果

javascript - 在新页面上显示预览

Javascript/PHP 重定向

android - 带有导航栏的标题内右对齐的 div 中断到另一行