Javascript 如何使用JS按今天的日期对LI进行排序
因此: 我有一个引导模板上的定价表,其中有7列,一周中的每一天一列,用于显示俱乐部的活动。相当标准。看起来是这样的:Javascript 如何使用JS按今天的日期对LI进行排序,javascript,jquery,twitter-bootstrap,date,Javascript,Jquery,Twitter Bootstrap,Date,因此: 我有一个引导模板上的定价表,其中有7列,一周中的每一天一列,用于显示俱乐部的活动。相当标准。看起来是这样的: <ul class="calen_table"> <li class="calen_block"> <h3>Sunday</h3> <div class="calen"> <div class="calen_figure">
<ul class="calen_table">
<li class="calen_block">
<h3>Sunday</h3>
<div class="calen">
<div class="calen_figure">
<span class="calen_number">Style</span>
</div>
</div>
<ul class="stuff">
<li>This!</li>
<li>This!</li>
<li>This!</li>
<li>This!</li>
<li>This!</li>
<li>This!</li>
</ul>
<div class="calfooter">
<a href="#" class="action_button">Promo</a>
</div>
</li>
<li class="calen_block">
<h3>Monday</h3>
<div class="calen">
<div class="calen_figure">
<span class="calen_number">Style</span>
</div>
</div>
<ul class="stuff">
<li>This!</li>
<li>This!</li>
<li>This!</li>
<li>This!</li>
<li>This!</li>
<li>This!</li>
</ul>
<div class="calfooter">
<a href="#" class="action_button">Promo</a>
</div>
</li>
and so on
我想做的是创建一个脚本,使每个列的顺序由一周中的哪一天决定-因此,如果用户在周日访问该站点,列表将显示周日、周一、周二。。。;如果用户在星期三访问该站点,列表将显示星期三、星期四、星期五
我一直都希望有所有7个显示,但想在一周的一天来设置顺序
我知道var day\u of_week=date.getDay;将得到我一周中的某一天,0-6分别是星期日和星期六。如果我有7组7,并且有一个触发器来显示给定日期的正确集合,我就是不知道如何最好地将其应用到这个案例中;或者,如果实际可以洗牌
任何想法都值得欣赏。我会选择这样的方法:
var blocks = $('.calen_block');
var today = new Date();
var day = today.getDay();
var temp = blocks.splice(0,day); //remove all the days before current day
temp = temp instanceof Array ? temp : [temp]; //splice doesn't return an array if you splice 1 element
blocks = blocks.concat(temp); // add the elements on after the current day
//empty the wrapper div and add them in the correct order
这种方法从html页面开始,在该页面中,日期从周一添加到周日。欢迎使用SO。恐怕任何想法和问题都被认为是离题的。请努力并回答更具体的问题。你可以看看。@isherwood-道歉;“我明白了,我知道在来支援堡垒之前我应该走得更远。@chenasraf-这看起来是个完美的解决方案!”!非常感谢,非常感谢!我能够将它与上面链接的tinysort结合使用来实现我的目标。我感谢你的意见!