2017-02-06 21 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

相關問題