2014-01-22 107 views
0

我正在編輯現有系統,他們使用Calendar.setup而不是jquery datepicker。我已經建議datepicker比calendar.setup更高級,但是他們仍然想使用calendar.setup。Javascript Calendar.setup獲取選定日期

我的問題是,我不知道如何獲取選定日期的值。

Calendar.setup 
    (
     { 
      inputField : 'txtDate',  // ID of the input field 
      ifFormat : "%Y-%m-%d",  // The Date Format 
      button  : 'txtDate'  // ID of the button 
     } 
    ); 

回答

1

試試這個:

Calendar.setup 
    (
     { 
      inputField : 'txtDate',  // ID of the input field 
      ifFormat : "%Y-%m-%d",  // The Date Format 
      button  : 'txtDate',  // ID of the button 
      onSelect : function(){ 
           var calDate = this.selection.get(); 
           var calHours = new String(this.getHours()); 
           var calMinutes = new String(this.getMinutes()); 
           var calTime = ((calHours.length == 1) ? '0'+calHours : calHours) + ((calMinutes.length == 1) ? '0'+calMinutes : calMinutes); 
      } 
     } 
    ); 
+2

你可能想給你的代碼的簡短說明。 –

+0

嗨,我覺得這個帖子很有幫助。但有幾個問題,取得的日期是這樣的「20140520」,我如何格式化爲「Y/m/d」? – user1149244

+1

想通了,我們可以使用this.selection.print(格式,分隔符)。文檔以供參考:http://www.dynarch.com/jscal/ – user1149244

0
var cal=Calendar.setup 
    (
     { 
      inputField : 'txtDate',  // ID of the input field 
      ifFormat : "%Y-%m-%d",  // The Date Format 
      button  : 'txtDate',  // ID of the button 

     }) 
var seldate=cal.date 
+0

請編輯更多信息。僅限代碼和「嘗試這個」的答案是不鼓勵的,因爲它們不包含可搜索的內容,也不解釋爲什麼有人應該「嘗試這個」。 – abarisone

+0

歡迎來到Stack Overflow!儘管這段代碼可以解決這個問題,但[包括一個解釋](// meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers)確實有助於提高您的帖子的質量。請記住,您將來會爲讀者回答問題,而這些人可能不知道您的代碼建議的原因。也請儘量不要使用解釋性註釋來擠佔代碼,因爲這會降低代碼和解釋的可讀性! – FrankerZ

相關問題