gpt4 book ai didi

javascript - 如何使用矩比较一周中的天数

转载 作者:行者123 更新时间:2023-12-03 07:11:24 26 4
gpt4 key购买 nike

我有一个这样的结构:

<ul id="list">
<li data-day="monday">BlaBla</li>
<li data-day="friday">BlaBla</li>
<li data-day="tuesday">BlaBla</li>
</ul>

我想读取该数据属性,然后检查代表的星期几,例如:

   $('#list').each(function(){
var day = $($this).data('day'); //day = monday
//MAKE SOMETHING BETTER THAN A BUNCH OF 'IF'S CONDICIONAL
//TO COMPARE THE DAY AND RELATE IT TO THE NUMBER OF THE WEEK.
//Now using `momentjs` I need to relate monday with the number day of the week. Knowing that monday is equivalent of 1.
if(day = "monday"){ var numDay = 1}
else if(day = "sunday"){ var numDay = 2}



});

最佳答案

这应该可以做到:

console.log(moment().day("Monday").day());

docs

关于javascript - 如何使用矩比较一周中的天数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36604862/

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