9

que estoy usando esta marcadojQuery selector de fechas - las opciones de modificación de los datos de atributos

<label> Date <input type="text" data-datepicker="{maxDate: '+1d'}" /></label> 
<label> Another date <input type="text" data-datepicker="" /></label> 
<script> 
$('[data-datepicker]').each(function() { 
     // init the options var with some default values (dateFormat etc) 
     // that can be overridden by the data-datepicker values 
     // also, new values can be added to the options from data-datepicker 
     // such as in the above example "maxDate" 
     var options = TODO;  

     $(this).datepicker(options); 
}); 
</script> 

que no se sabe muy bien por dónde empezar con el objeto que las opciones .. A partir de los valores por defecto parece una buena iniciar

var options = { dateFormat: 'yy-mm-dd }; 

Pero entonces, ¿cómo puedo añadir/sobrescribir con los valores del atributo de datos .. yo no sé

Respuesta

12

con esta marcado (debe formatear el atributo "datos" como éste, así que son reconocidos como objetos):

<label> Date <input type="text" data-datepicker='{"maxDate": "+1d"}' /></label> 
<label> Another date <input type="text" data-datepicker='{ "dateFormat": "dd-mm-yy"}' /></label> 

Se podría hacer:

$('[data-datepicker]').each(function() { 
    //standard options 
    var options = { dateFormat: "yy-mm-dd"}; 
    //additional options 
    var additionalOptions = $(this).data("datepicker"); 
    //merge the additional options into the standard options and override defaults 
    jQuery.extend(options, additionalOptions); 


     $(this).datepicker(options); 
}); 

violín aquí: http://jsfiddle.net/WrRte/

+0

Gracias por su ayuda. – Ivar

Cuestiones relacionadas