Materializecss 日期选择器仅在过去几天
Materializecss Date Picker only days in the past
我正在尝试为用户的生日创建一个输入字段。为此,我希望他们只在 select 年前。
我该如何实现?我尝试在 selectYears
属性 中输入负数,但没有成功。
HTML:
<div class="col s12">
<label for="birthday">Birthday</label>
<input id="birthday" value="{{ user.birthday }}" type="date" name="birthday" class="datepicker">
</div>
JavaScript:
$('.datepicker').pickadate(
{
selectMonths: true,
selectYears: -100
});
这是您设置年份的方式:
var d = new Date();
d.setFullYear( d.getFullYear() - 100 );
$('.datepicker').pickadate(
{
selectMonths: true,
selectYears: true,
min: d,
max: new Date()
});
http://jsfiddle.net/rpu61tf2/3/
当您希望允许用户select下拉菜单中的年份
时,您设置selectYears: true
var d = new Date();
d.setFullYear( d.getFullYear() - 100 );
$('.datepicker').pickadate(
{
selectMonths: true,
selectYears: d,
max: new Date()
});
这实际上会给出过去 100 年的完整列表。
我正在尝试为用户的生日创建一个输入字段。为此,我希望他们只在 select 年前。
我该如何实现?我尝试在 selectYears
属性 中输入负数,但没有成功。
HTML:
<div class="col s12">
<label for="birthday">Birthday</label>
<input id="birthday" value="{{ user.birthday }}" type="date" name="birthday" class="datepicker">
</div>
JavaScript:
$('.datepicker').pickadate(
{
selectMonths: true,
selectYears: -100
});
这是您设置年份的方式:
var d = new Date();
d.setFullYear( d.getFullYear() - 100 );
$('.datepicker').pickadate(
{
selectMonths: true,
selectYears: true,
min: d,
max: new Date()
});
http://jsfiddle.net/rpu61tf2/3/
当您希望允许用户select下拉菜单中的年份
时,您设置selectYears: true
var d = new Date();
d.setFullYear( d.getFullYear() - 100 );
$('.datepicker').pickadate(
{
selectMonths: true,
selectYears: d,
max: new Date()
});
这实际上会给出过去 100 年的完整列表。