在焦点上,我的选择器创建一个动态ID,用于使用datepicker对象,只有datepickers月,年和上一个/下一个按钮不起作用。
$(document).on('focus', ".gfield_list_container tr td:nth-child(2) input" , function(){
// Gforms doesn't give list fields new ids so we must do it ourselves to enable date picker to work
$(this).attr('id', makeid());
$(this).removeClass('hasDatepicker');
$(this).datepicker({ dateFormat: 'dd/mm/yy' });
});
见到这里:
我搜了一下,发现了这个:
$(this).live('focus', function(){
$(this).datepicker({
dateFormat: 'dd/mm/yy',
changeMonth: true,
changeYear: true,
yearRange: '1930:'+(new Date).getFullYear()
});
});
使用这种方法,我必须先在日期字段外单击,然后在其中单击以激活日期选择器。一旦它可见,而前一个/下一个按钮和几个月/几年现在似乎正常运行,我仍然无法选择我需要的日期,月份将不会超过三月?
答案 0 :(得分:-1)
您是否正在使用jQuery UI中的datepicker?如果是,请从他们显示的代码开始作为示例 https://jqueryui.com/datepicker/
然后一旦它工作,根据需要调整它。
无论如何,如果你从你给出的例子开始工作,也许可以尝试:
$(document).on('focus', ".gfield_list_container tr td:nth-child(2) input" , function(){
// Gforms doesn't give list fields new ids so we must do it ourselves to enable date picker to work
$(this).attr('id', makeid());
$(this).datepicker({
dateFormat: 'dd/mm/yy',
changeMonth: true,
changeYear: true,
yearRange: '1930:'+(new Date).getFullYear()});
});