Sto utilizzando un plug-in per il calendario e desidero popolare la data corrente in un campo di testo. Come posso farlo usando jquery?Come ottenere la data corrente usando jquery?
6
A
risposta
12
È possibile ottenere current date in JavaScript:
var now = new Date();
Se si utilizza jQuery DatePicker si può applicare su qualsiasi campo di testo come questo:
$('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
Getta un nome di tag su quel selettore e verrà eseguito più velocemente. Sostituisci ''.youTextFieldClass'' con'' input.youTextFieldClass''. – chprpipr
2
Potete trovare il campione here.
<input type="text" id="datepicker">
$("#datepicker").datepicker({dateFormat:"dd M yy"}).datepicker("setDate",new Date());
quale plugin di calendario? puoi mostrarci il link? – Reigel