我正在制作一个日历,需要阻止前几天(当天之前),数月和数年(有3种可能的观看方式)。
我可以获得当前日期。问题是,如何在每个div块中添加特定的类,该div块在当前日期(类“今天”)之前显示为值。
看看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日)。 问题是,在使用“今天”类的div块之前找到所有div块的方法是什么,并为每个块添加特定的类?
之前div块中可能有不同的类。
答案 0 :(得分:3)
使用prevAll获取以前的兄弟姐妹:
$( "div.today" ).prevAll().addClass('blocked');