2011-01-17 30 views

Trả lời

12

Bạn có thể nhận current date in JavaScript:

var now = new Date(); 

Nếu bạn đang sử dụng jQuery DatePicker bạn có thể áp dụng nó trên bất kỳ textfield như thế này:

$('input.youTextFieldClass').datepicker({ dateFormat: 'mm/dd/yy', 
            changeMonth: true, 
            changeYear: true, 
            yearRange: '-70:+10', 
            constrainInput: false, 
            duration: '', 
            gotoCurrent: true}); 

If you want to set current date in textfields as page load:

$("input.youTextFieldClass").datepicker('setDate', new Date()); 
+3

Ném tên thẻ trên bộ chọn đó và nó sẽ chạy nhanh hơn. Thay thế ''.youTextFieldClass'' bằng'' input.youTextFieldClass''. – chprpipr

2

Bạn có thể tìm thấy mẫu here.

<input type="text" id="datepicker"> 
$("#datepicker").datepicker({dateFormat:"dd M yy"}).datepicker("setDate",new Date()); 
Các vấn đề liên quan