JavaScript: jQuery Datepicker – mise en évidence simple de jours spécifiques, qui peut vous aider? (source à l’intérieur)

Je veux utiliser le Datepicker pour mettre en évidence des dates spécifiques. Voici mon dernier code:

 var dates = [30/04/2010, 01/05/2010]; $(function(){ $('#datepicker').datepicker({ numberOfMonths: [2,3], dateFormat: 'dd/mm/yy', beforeShowDay: highlightDays }); function highlightDays(date) { for (var i = 0; i < dates.length; i++) { if (dates[i] == date) { return [true, 'highlight']; } } return [true, '']; } });  

mon CSS est:

 #highlight, .highlight { background-color: #cccccc; } 

Eh bien, le calendrier apparaît, mais rien n’est mis en évidence. Où est le problème dans mon code? Si quelqu’un pouvait aider, ce serait génial.

Une autre option / solution pourrait être: désactiver toutes les dates, mais ne rendre disponible que les dates dans un tableau.

Merci!

laissez vous raconter certains des problèmes …

1 . var dates = [30/04/2010, 01/05/2010];

ne stockera pas vos dates comme prévu … il effectuera des opérations mathématiques …

2. changez-le en chaîne mais dans ce format: mm/dd/yy
alors, vous devriez avoir quelque chose comme:

 var dates = ['04/30/2010', '05/01/2010']; 

3. utiliser cette fonction:

 function highlightDays(date) { for (var i = 0; i < dates.length; i++) { if (new Date(dates[i]).toString() == date.toString()) { return [true, 'highlight']; } } return [true, '']; } 

4. CSS en tant que:

 td.highlight { background-color: red; border: 1px blue solid; } 

5. démo

Il y a un problème de fuseau horaire.

 function highlightDays(date) { for (var i = 0; i < dates.length; i++) { if (new Date(dates[i]).toString().substr(0, 16) == date.toString().substr(0, 16)) { return [true, 'highlight']; } } return [true, '']; }