2014-05-08 85 views
1

我想在同一頁面上使用多個日期輸入,其中一些必須使用格式yy-mm-dd和其他格式yy-mm。當我爲yy-mm格式添加jQuery代碼格式輸入與yy-mm-dd格式丟失日期,只有幾個月和幾年是可見的?如何在jquery中使用不同的日期格式輸入日期

$(function() {  
    var currentDate = new Date(); 
    $(".datepicker").datepicker({ dateFormat: "yy-mm-dd" }); 
    $(".datepicker").datepicker("setDate",currentDate);  
}); 

$(function() { 
    $('.month-picker').datepicker({ 
     changeMonth: true, 
     changeYear: true, 
     showButtonPanel: true, 
     dateFormat: 'yy-mm', 
     onClose: function(dateText, inst) { 
      var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val(); 
      var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val(); 
      $(this).datepicker('setDate', new Date(year, month, 1)); 
     } 
    }); 
}); 

回答

1

我不認爲yy-mmyy-mm-dd有任何conflicts.I嘗試同樣的檢查這Fiddle。無論是文件的格式爲同一頁上

+0

你是對的。問題是CSS'.ui-datepicker-calendar {display:none;}'。這個CSS只能應用於特定的HTML輸入嗎?我想只顯示monthpicker的月份和年份。 – Galuk

相關問題