本文介绍了点击时改变日数颜色 - 不是背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在完整日历中的任何一天点击时更改日期编号颜色。我尝试显示点击的日期已激活。
I need to change the day number color when I click in any day in full calendar. I'm trying to show that the day clicked is activated.
我尝试使用推荐的textColor,color,borderColor和backgroundColor,但只有最后一个可以使用。 p>
I tried to use the recommended textColor, color, borderColor and backgroundColor but only the last one works.
dayClick: function(date, jsEvent, view) {
$(this).css('textColor', 'red');
},
谢谢。
Thank you.
推荐答案
使用
$('#calendar').fullCalendar({
dayClick: function (date) {
var moment = date.toDate();
MyDateString = moment.getFullYear() + '-'
+ ('0' + (moment.getMonth() +1) ).slice(-2)
+ "-" +('0' + moment.getDate()).slice(-2);
$('[data-date='+MyDateString+']').css({"color": "red", "backgroundColor": "yellow", "borderBottom": "5px solid #ccc"});
}
});
说明:
Explanation:
var moment = date.toDate();
这会将日期字符串更改为javascript日期对象
This changes the date string to javascript date object
MyDateString = moment.getFullYear() + '-'
+ ('0' + (moment.getMonth() +1) ).slice(-2)
+ "-" +('0' + moment.getDate()).slice(-2);
此代码将日期格式更改为2016-07-29
This code changes date format to 2016-07-29
$('[data-date='+MyDateString+']').css({"color": "red", "backgroundColor": "yellow", "borderBottom": "5px solid #ccc"});
检查我们的HTML属性data-date =2016-07-29并应用风格相应
This check in our html where attribute data-date="2016-07-29" and applies the style accordingly
希望这有助于
这篇关于点击时改变日数颜色 - 不是背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!