gpt4 book ai didi

Jquery 将类添加到具有特定类的 div block 之前的 div block

转载 作者:行者123 更新时间:2023-12-01 07:57:35 26 4
gpt4 key购买 nike

我正在制作一个日历,需要阻止前几天(今天之前)、几个月和几年(有 3 种可能的查看方式)。

我可以获得当前日期。问题是,如何向每个在当前日期之前显示值的 div block 添加特定的类(“今天”类)。

看一下 HTML 结构:

<div class="days">
<div class="not-in-month day-button">31</div>
<div class="day-button">1</div>
<div class="day-button">2</div>
<div class="day-button">3</div>
<div class="day-button">4</div>
<div class="saturday day-button">5</div>
<div class="sunday day-button">6</div>
<div class="day-button">7</div>
<div class="day-button">8</div>
<div class="day-button">9</div>
<div class="selected today day-button">10</div>
<div class="day-button">11</div>
<div class="saturday day-button">12</div>
<div class="sunday day-button">13</div>
<div class="day-button">14</div>
<div class="day-button eventday">15</div>
<div class="day-button">16</div>
<div class="day-button">17</div>
<div class="day-button eventday">18</div>
<div class="saturday day-button">19</div>
<div class="sunday day-button">20</div>
<div class="day-button">21</div>
<div class="day-button">22</div>
<div class="day-button">23</div>
<div class="day-button">24</div>
<div class="day-button">25</div>
<div class="saturday day-button">26</div>
<div class="sunday day-button">27</div>
<div class="day-button">28</div>
<div class="day-button">29</div>
<div class="day-button">30</div>
<div class="not-in-month day-button">1</div>
<div class="not-in-month day-button">2</div>
<div class="not-in-month saturday day-button">3</div>
<div class="not-in-month sunday day-button">4</div>
<div class="not-in-month day-button">5</div>
<div class="not-in-month day-button">6</div>
<div class="not-in-month day-button">7</div>
<div class="not-in-month day-button">8</div>
<div class="not-in-month day-button">9</div>
<div class="not-in-month saturday day-button">10</div>
<div class="not-in-month sunday day-button">11</div>
</div>

这是几天的结构。月和年与此类似。正如您所看到的,今天日期始终标有“今天”类别(2014 年 4 月 10 日)。问题是,如何找到类为“today”的 div block 之前的所有 div block ,并为每个 block 添加特定的类?

之前 div block 中可能有不同的类。

最佳答案

使用 prevAll 获取之前的同级:

$( "div.today" ).prevAll().addClass('blocked');

关于Jquery 将类添加到具有特定类的 div block 之前的 div block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22982827/

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