JavaScript:jQuery Datepicker - 简单突出特定的日子,谁可以帮忙? (来源内) [英] JavaScript: jQuery Datepicker - simple highlighting of specific days, who can help? (source inside)
问题描述
我想使用Datepicker突出显示特定的日期。这是我最新的代码:
< script type =text / javascript>
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< ; date.length; i ++){
if(dates [i] == date){
return [true,'highlight'];
}
}
return [true,''];
}
});
< / script>
我的CSS是:
#highlight,.highlight {
background-color:#cccccc;
}
日历出来了,但没有任何突出显示。我的代码中的问题在哪里?
如果有人可以帮助那将是很棒的。
另一个选项/解决方案可能是:禁用所有日期,但只能在数组中使用日期。 p>
谢谢!
告诉你一些问题...
1。 var dates = [30/04/2010,01/05/2010];
不会按预期存储您的日期...它将进行数学运算...
2. 将其更改为字符串,但格式如下: mm / dd / yy
所以你应该有这样的东西:
var dates = ['04 / 30/2010','05 / 01/2010'];
3. 使用此功能:
function highlightDays(date){
for(var i = 0; i&长度; i ++){
if(new Date(dates [i])。toString()== date.toString()){
return [true,'highlight'];
}
}
return [true,''];
}
4. CSS as:
td.highlight {
background-color:red;
border:1px blue solid;
}
5. 演示
i want to use the Datepicker for highlighting specific dates. Here is my latest code:
<script type="text/javascript">
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, ''];
}
});
</script>
my CSS is:
#highlight, .highlight {
background-color: #cccccc;
}
Well the calendar comes up, but there is nothing highlighted. Where is the problem in my code? If anyone could help that would be great.
Another option/solution could be: disable all dates, but make available only dates in an array.
Thanks!
let tell you some of the problems...
1 . var dates = [30/04/2010, 01/05/2010];
would not store your dates as expected... it will do math operations...
2. change it to string but in this format: mm/dd/yy
so, you should have something like:
var dates = ['04/30/2010', '05/01/2010'];
3. use this function:
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 as:
td.highlight {
background-color: red;
border: 1px blue solid;
}
5. demo
这篇关于JavaScript:jQuery Datepicker - 简单突出特定的日子,谁可以帮忙? (来源内)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!