我正在使用materializecss.com Datepicker.当我尝试使用jquery设置日期时,日期不会设置.这是我的代码: –
// Materialize Date Picker
window.picker = $('.datepicker').pickadate({
selectMonths: true, // Creates a dropdown to control month
selectYears: 100, // Creates a dropdown of 15 years to control year
format: 'dd/mm/yyyy'
});
<input type="text" id="Date" class="datepicker" />
在Button的Click事件中,我设置日期: –
$("#Date").val('23/01/2015');
当我打开datepicker时,它会显示今天的日期.
如何在物化日期选择器中设置日期?
解决方法:
Materialize datepicker是一个经过修改的pickadate.js选择器.
在他们的API docs,这是如何设置选择器:
>获取选择器:
var $input = $('.datepicker').pickadate()
// Use the picker object directly.
var picker = $input.pickadate('picker')
>设置日期:
// Using arrays formatted as [YEAR, MONTH, DATE].
picker.set('select', [2015, 3, 20])
// Using JavaScript Date objects.
picker.set('select', new Date(2015, 3, 30))
// Using positive integers as UNIX timestamps.
picker.set('select', 1429970887654)
// Using a string along with the parsing format (defaults to `format` option).
picker.set('select', '2016-04-20', { format: 'yyyy-mm-dd' })