2017-02-06 27 views
0

在焦点上,我的选择器创建了一个动态编号用于使用datepicker对象,只有datepickers的月份,年份和prev/next按钮不起作用。未被捕获缺少此日期选择器的实例数据

$(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' }); 
}); 

这里看到:

seen here

我搜索周围一点点,发现这个:

$(this).live('focus', function(){ 
    $(this).datepicker({ 
     dateFormat: 'dd/mm/yy', 
     changeMonth: true, 
     changeYear: true, 
     yearRange: '1930:'+(new Date).getFullYear()   
    }); 
}); 

用这种方法我得先日期字段外单击,然后单击在它内部激活日期选择器。一旦它可见,而上一个/下一个按钮和几个月/年现在似乎功能正常,我仍然无法选择我需要的日期,并且月份不会超过三月?

+1

,你可以创建一些小提琴或JSsnippet,所以这将是我们更容易帮助你吗? – yash

回答

0

您是否使用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()}); 
}); 
+0

使用上面的select和previous/next现在似乎工作,但是,由于某些原因,我似乎无法循环到3月份。另一个问题是,点击日期后,我会立即回到窗口的顶部,而没有从日期选择器中选择任何内容。值得注意的是,我在这个页面上有3个日期选择器。 – cookie

相关问题