我想要两个独立的字段,一个是YY,一个是MM。目前我已经实现了这个功能,但是只有一个字段。以下是目前的情况:
目前的情况截图 <input id="residenceyears" name="residenceyears" type="text" placeholder="YY/MM" class="input yyMM numeric-only">
这是JS函数:
<script type="text/javascript">
$('.yyMM').datepicker({
changeMonth: true,
changeYear: true,
monthNames: ["1","2","3","4","5","6","7","8","9","10","11","12"],
yearRange: "-100:+0",
dateFormat: 'yy/mm',
onClose: function() {
var iMonth = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var iYear = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(iYear, iMonth, 1));
},
beforeShow: function() {
if ((selDate = $(this).val()).length > 0)
{
iYear = selDate.substring(selDate.length - 4, selDate.length);
iMonth = jQuery.inArray(selDate.substring(0, selDate.length - 5), $(this).datepicker('option', 'monthNames'));
$(this).datepicker('option', 'defaultDate', new Date(iYear, iMonth, 1));
$(this).datepicker('setDate', new Date(iYear, iMonth, 1));
}
}
我想要实现的是这个效果:应该是这样的
});