search

Home  >  Q&A  >  body text

当获取的是一组元素时,这样写为什么不行,我记得之前也有类似的写法啊??

$('li').css('color','red')

为什么不能这样直接设置


checkcheck2931 days ago1114

reply all(3)I'll reply

  • 数据分析师

    数据分析师2017-09-30 23:01:43

    When a set of elements is obtained, why doesn’t it work like this? I remember there was a similar way of writing it before? ? -PHP Chinese website Q&A-When a set of elements is obtained, why can't it be written like this? I remember that there was a similar way of writing it before? ? -PHP Chinese website Q&A

    Please watch and learn.

    reply
    0
  • /zt

    /zt2017-09-26 08:07:17

    Okay, but the settings are all a single color red.

    reply
    0
  • 迷茫

    迷茫2016-12-20 09:36:04

      $("li").each(function(index, element) {
                if (index % 2) {
                    $(this).css('color','blue')
                }
            })

    这里是2的倍数你可以用奇偶解决,可如果是3的倍数呢,如果,要按彩虹色呢,1,4,7红色,2,5,8蓝色,3,6,9黑色,或者别的,


    reply
    0
  • Cancelreply