下拉列表中的下一个7天 [英] next 7 days in drop-down list
本文介绍了下拉列表中的下一个7天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望接下来的7天出现在下拉列表中。然而,我的代码似乎没有工作。
请注意,日期格式必须是 yyyy-mm-dd
。
请你帮我一下。以下是我的代码:
function formatDate(date){var d = new Date(date),month =''+(d.getMonth ()+ 1),day =''+ d.getDate(),year = d.getFullYear(); if(month.length <2)month ='0'+ month; if(day.length <2)day ='0'+ day;返回[year,month,day] .join(' - ');} var curr = new Date; var first = curr.getDate()var firstday =(new Date(curr.setDate(first)))。toString() ; for(var i = 0; i <7; i ++){var next = new Date(curr.getTime()); next.setDate(first + i); (+)< / option>';} $(#datemenu1)。append .html(< option> PICK A DATE< / option>);
< html>< select id =datemenu1> < option> PICK A DATE< / option> < / select>< script src =http://code.jquery.com/jquery.min.js>< / script>< script src =Text-1.js>< / script>> strong text< / html>
$ b
解决方案
行到您的代码的顶部:
var options =;
I'd like the next 7 days to appear in a drop-down list. However my code doesn't seem to work.
Please note that the date format has to be yyyy-mm-dd
.
Could you please help me. Here is my code:
function formatDate(date) {
var d = new Date(date),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2) month = '0' + month;
if (day.length < 2) day = '0' + day;
return [year, month, day].join('-');
}
var curr = new Date;
var first = curr.getDate()
var firstday = (new Date(curr.setDate(first))).toString();
for (var i = 0; i < 7; i++) {
var next = new Date(curr.getTime());
next.setDate(first + i);
options += '<option>' + formatDate((next.toString())) + '</option>';
}
$("#datemenu1").append(options);
$("#datemenu1").html("<option>PICK A DATE</option>");
<html>
<select id="datemenu1">
<option>PICK A DATE</option>
</select>
<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="Text-1.js"></script>strong text
</html>
解决方案
Add this line to the top of your code:
var options = "";
这篇关于下拉列表中的下一个7天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文