Javascript设置日期的最小和最大属性

时间:2015-03-11 03:37:43

标签: javascript datepicker

我想限制日期选择超过当前日期的7天..帮助我

<script> 
var date = new Date(); 
var startdate = date.getFullYear().toString()+"-"+ date.getMonth.toString()+"-"+date.getDate()+1.toString(); 
var maxdate =date.getFullYear().toString()+"-"+ date.getMonth.toString()+"-"+date.getDate()+6.toString();
document.getElementById("demo").setAttribute("min",startDate);
document.getElementById("demo").setAttribute("max",maxdate); 
</script>

1 个答案:

答案 0 :(得分:0)

这里有很多方法可以做到这一点:

var date = new Date();
var startDate = date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate();
maxDate = startDate.split('-').map(Number);
maxDate[2] += 7;


demo.max = maxDate.join('-');
demo.min = startDate;