本日から1週間分の日付と曜日を表示させる方法を教えてください。
以下現状のコードです。
HTML
<div class="dateSlide"> <ul class="dateSlideList"> <li class="date01"></li> <li class="date02"></li> <li class="date03"></li> <li class="date04"></li> <li class="date05"></li> <li class="date06"></li> <li class="date07"></li> </ul> </div>
JS
$(function(){ var now = new Date(); var m = now.getMonth() + 1; var d = now.getDate(); var wd = ['日', '月', '火', '水', '木', '金', '土']; var wday = "(" + wd[ now.getDay() ] + ")" ; var d2 = now.getDate() + 1; var w2 = "(" + wd[ now.getDay() + 1 ] + ")" ; var d3 = now.getDate() + 2; var w3 = "(" + wd[ now.getDay() + 2 ] + ")" ; var d4 = now.getDate() + 3; var w4 = "(" + wd[ now.getDay() + 3 ] + ")" ; var d5 = now.getDate() + 4; var w5 = "(" + wd[ now.getDay() + 4 ] + ")" ; $('.date01').text(m + '月' + d + '日' + wday); $('.date02').text(m + '月' + d2 + '日' + w2); $('.date03').text(m + '月' + d3 + '日' + w3); $('.date04').text(m + '月' + d4 + '日' + w4); $('.date05').text(m + '月' + d5 + '日' + w5); });
上記だと、おそらく曜日の繰り返しができなくなってエラーになります。まったく良くわからないまま作っているので、スマートな書き方があれば教えていただきたいです。。。

回答4件
あなたの回答
tips
プレビュー