2009-09-07 79 views
1

我在尋找一個簡單的集成日期選擇對象,當有人專注於一個特定的文本框這將被觸發。當用戶點擊或關注文本框時,日期選擇器界面應該彈出,並顯示當前日期,用戶可以輕鬆選擇日期。完成後,文本框的格式應爲YYYY-MM-DD(mysql日期格式)。使用Javascript/jQuery的日期選擇器

這也有可能需要2個文本框採摘的開始和結束日期。

任何想法?

回答

3

你見過jQuery用戶界面的datepicker?它完成了以上所有內容。

HTML

<input type="text" id="datepicker" size="30"/> 

的JavaScript

$('#datepicker').datepicker({ dateFormat: 'yy-mm-dd' }); 
0

你可以嘗試Zebra_Datepicker, a lightweight datepicker jQuery plugin

下面是一個例子answe同時提出你的問題。 假設你有兩個文本框,一個個,起始日期和一個與結束日期,就像這樣:

<input type="text" name="start_date" id="start_date"> 
<input type="text" name="end_date" id="end_date"> 

現在,在你的JavaScript文件,後您包括jQuery的,Zebra_Datepicker,及其相關的CSS文件,你會使用類似:

$(document).ready(function() { 
    $('#start_date').Zebra_DatePicker({ 
     direction: true,   // future-only calendar, starting today 
     format:  'YYYY-MM-DD', // the format you want 
     pair:  $('#end_date') // we pair the two elements 
    });  
    $('#end_date').Zebra_DatePicker({ 
     direction: true,   // future-only calendar, starting today 
            // (unless a date is selected in the other 
            // element when the date picker will become 
            // future-only, starting that particular date) 
     format:  'YYYY-MM-DD'  // the format you want 
    });  
}); 
相關問題