我的应用程序中有多个日期选择器。但是,日期选择器之一应为月份选择器(ReportPeriod对象),而其余对象(带有Style2类)应使用默认的标准化日期选择器。我是Jquery新手,谢谢!
我当前在同一脚本中加载了两个日期选择器,这可能是在问题发生时发生的,因为应用的最新属性显然会影响所有日期选择器对象。
jQuery:
$('#ReportPeriod').datepicker({
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'MM yy',
onClose: function (dateText, inst) {
$(this).datepicker('setDate', new Date(inst.selectedYear, inst.selectedMonth, 1));
var date = new Date(inst.selectedYear, inst.selectedMonth, 1);
period = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2);
console.log(period);
VerifyReportingPeriod(period);
}
});
$('.Style2').datepicker();
HTML:
<td class="alignleft"><input type="text" id="ReportPeriod" required class="Style1"/></td>
<td class="alignleft"><input type="text" id="MissionMilestone1" class="Style2" /></td>
CSS:
.Style1 {
width: 220px;
border: 1px solid #ccc;
border-radius: 4px;
height: 30px;
}
.Style2 {
width: 150px;
height: 30px;
border: 1px solid #ccc;
border-radius: 4px;
}
.ui-datepicker-calendar { (I want this only applied to my ReportPeriod Object)
display: none;
}
当前代码显示月份选择器显示正确,但是常规日期选择器(带有Style2类)也将日期选择器显示为月份选择器。