0

私はこのような日のリストを持っています、

<ul>
    <li class="dark"><a rel="25" class="0725" style="color: rgb(255, 255, 255);">25</a></li>
    <li class="dark"><a rel="26" class="0726" style="color: rgb(255, 255, 255);">26</a></li>
    <li class="dark"><a rel="27" class="0727" style="color: rgb(255, 255, 255);">27</a></li>
    <li class="dark"><a rel="28" class="0728" style="color: rgb(255, 255, 255);">28</a></li>
    <li class="dark"><a rel="29" class="0729" style="color: rgb(255, 255, 255);">29</a></li>
    <li class="dark"><a rel="30" class="0730" style="color: rgb(255, 255, 255);">30</a></li>
    <li class="dark first"><a rel="31" class="0731" style="color: rgb(255, 255, 255);">31</a></li>
    <li class="dark"><a rel="1" class="0801" style="color: rgb(255, 255, 255);">1</a></li>
    <li class="dark"><a rel="2" class="0802" style="color: rgb(255, 255, 255);">2</a></li>
    <li class="dark"><a rel="3" class="0803" style="color: rgb(255, 255, 255);">3</a></li>
    <li class="dark"><a rel="4" class="0804" style="color: rgb(255, 255, 255);">4</a></li>
    <li class="dark"><a rel="5" class="0805" style="color: rgb(255, 255, 255);">5</a></li>
    <li class="dark"><a rel="6" class="0806" style="color: rgb(255, 255, 255);">6</a></li>
    <li class="dark"><a rel="7" class="0807" style="color: rgb(255, 255, 255);">7</a></li>
    <li class="dark"><a rel="8" class="0808" style="color: rgb(255, 255, 255);">8</a></li>
    <li class="dark"><a rel="9" class="0809" style="color: rgb(255, 255, 255);">9</a></li>
    <li class="dark"><a rel="10" class="0810" style="color: rgb(255, 255, 255);">10</a></li>
    <li class="dark"><a rel="11" class="0811" style="color: rgb(255, 255, 255);">11</a></li>
    <li class="dark"><a rel="12" class="0812" style="color: rgb(255, 255, 255);">12</a></li>
</ul>

今日の色と前日の色を変えたいです。クラスは月日制です。

4

2 に答える 2

0

JS を使用します。

var d = new Date();
alert(d.getDate());
alert(d.getMonth());

d.getDate() は 1 から 31 までの数値を表示します。g.getMonth() は月 (0 から 11) を返します。

のクラスとして 0731 を使用する代わりに、ID として 0731 を入力し、ByID ゲッターを使用してスタイル クラスを更新します。

http://www.w3schools.com/jsref/jsref_obj_date.asp

これらの情報を使用して、今すぐ自分を助けることができます。

于 2012-07-31T14:59:47.953 に答える
0

このようなことを試してください

// get current date
var today = new Date();
// get days using getDate() and pad to 2 digits
var tdd = zeroPad(today.getDate(),2);
// get months using getMonth() and pad to 2 digits
var tmm = zeroPad(today.getMonth()+1,2);

// get current date
var yesterday = new Date();
// set date to date -1 ie yesterday
yesterday.setDate(today.getDate() - 1);
// get days using getDate() and pad to 2 digits
var ydd = zeroPad(yesterday.getDate(),2);
// get months using getMonth() and pad to 2 digits
var ymm = zeroPad(yesterday.getMonth()+1,2);

// concatenate strings to form class and use css() to set appropriate color
$('.'+tmm + tdd).css('background-color','red');
$('.'+ymm + ydd).css('background-color','blue');

今日の色を赤に、昨日の色を青に設定する必要があります。DateobjectSO answer here.css()から取得しzeroPad()た関数を使用します

作業例はこちら

于 2012-07-31T14:59:07.010 に答える