gpt4 book ai didi

javascript - datepicker 显示基于年份的日期 - JQuery

转载 作者:搜寻专家 更新时间:2023-10-31 20:59:33 25 4
gpt4 key购买 nike

我尝试根据选定的下拉列表加载当前年份和上一年(2017、2018)的日期范围。但是我的日期选择器只显示首先选择的年份。

I can show the years which is first selected. Example First selected year- 2017 means show the 2017 calender Second change selected year- 2018 means show the 2017 calender

HTML 代码:

 <?php $year = date('Y'); ?>
<select name="hyear" id="hyear" data-placeholder="Select Year" class="form-control chosen-select">
<option value="<?php echo $year ?>"><?php echo $year ?></option>
<option value="<?php echo ++$year ?>"><?php echo $year ?></option>
</select>

脚本代码:

 function updateDatePic(mindate, maxdate)
{
$('#hdate').datepick({
minDate: mindate,
maxDate: maxdate,
onSelect: function () {

}
});
}

$('#hyear').change(function () {
var year = $.trim($("#hyear").val());
var mindate = '01/01/' + year;
var maxdate = '12/31/' + year;
alert("mindate="+mindate+"...maxdate="+maxdate);
updateDatePic(mindate, maxdate);
});

请指教!

最佳答案

请使用此代码:

$( "#hdate" ).datepicker({   
dateFormat: 'dd/mm/yy',
changeMonth: true,
changeYear: true,
yearRange: '2017:2018'
});

关于javascript - datepicker 显示基于年份的日期 - JQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46702327/

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