简体   繁体   English

如何为所有TD添加类别

[英]How to add class to all TD

I am using jQuery with addClass to add class to some elements. 我使用带有addClass的jQuery将类添加到某些元素。 But for some reason not all "td" get the class assigned (the ones with the .currentmonth). 但是由于某种原因,并非所有的“ td”都获得了分配的类(带有.currentmonth的类)。

$("td").addClass("aaawwwasdsad");

https://jsfiddle.net/wheelq/7Lesommm/ https://jsfiddle.net/wheelq/7Lesommm/

Because other Javascript functions run later. 因为其他Javascript函数稍后运行。

Look : https://jsfiddle.net/p9kogsmL/14/ 看: https : //jsfiddle.net/p9kogsmL/14/

Define it into the end of calendar function : 将其定义到日历功能的末尾:

     ...

        document.getElementById("calendar").innerHTML += calendarTable;
        $("td").addClass("aaawwwasdsad");
      }

If you want to add a class to all td ,you have to use each loop. 如果要向所有td添加一个类,则必须使用each循环。 here is an example: 这是一个例子:

$("td").each(function(){
   $(this).addClass("aaawwwasdsad");
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM