2016-02-26 59 views
1

我試圖執行JQuery DatePicker w/ week no並以YYYYMMDD格式返回所選日期。當看着api for how to format date它說這可以通過使用dateFormat:「yy-mm-dd」來完成。但是,我無法以指定的格式返回日期。如何使用JQuery DatePicker以格式YYYYMMDD返回日期?

我能夠在「原始格式」,此代碼返回日期:

$(function DatePicker() { 
$("#datepicker").datepicker({ 
    onSelect: function(date) { 
    var date = $(this).datepicker('getDate'); 
    alert(date); 
('getDate').getDate(); 
    },  
    showWeek: true, 
    //showOn:"button", 
    firstDay: 1 
}); 
}); 

這裏是我試圖返回(顯示彈出)wewith格式「YYYYMMDD」代碼:

$(function DatePicker() { 
$("#datepicker").datepicker({ 
// dateFormat: 'yy-mm-dd', 
    onSelect: function() { 
     dateFormat: 'yy-mm-dd', 
     //var dateFormat = $(this).datepicker("option", "dateFormat"); 
     //$.(this).datepicker("option", "dateFormat", "yy-mm-dd"); //Senast insatt 
     alert(dateFormat); 
    },  
    showWeek: true, 
    firstDay: 1 
}); 

});

很顯然,我是JQuery的新手,對於JavaScript作爲一種語言來說相當新穎。

謝謝!

+1

你必須把這樣的 「ONSELECT」 函數的日期格式輸出。 '$('#datepicker')。datepicker({dateFormat:'yy-mm-dd',onSelect:function ....});' – Sapikelio

回答

1

檢查:

$("#datepicker").datepicker({ 
     dateFormat: 'yymmdd', 
     onSelect: function(v){ 
     alert(v); 
     },  
     showWeek: true, 
     firstDay: 1 
}); 

Test code herehttp://codepen.io/anon/pen/yOBwLo

+0

謝謝!這個竅門! =) – svenan

+0

如果它有用,請將它標記爲[answer](http://stackoverflow.com/help/accepted-answer)。 –

相關問題