Change day number color on click - not background

♀尐吖头ヾ 提交于 2019-12-12 19:25:40

问题


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.

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.


回答1:


Use

$('#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();

This changes the date string to javascript date object

MyDateString = moment.getFullYear() + '-'
                                    + ('0' + (moment.getMonth() +1) ).slice(-2)
                                    + "-" +('0' + moment.getDate()).slice(-2);

This code changes date format to 2016-07-29

$('[data-date='+MyDateString+']').css({"color": "red", "backgroundColor": "yellow", "borderBottom": "5px solid #ccc"});

This check in our html where attribute data-date="2016-07-29" and applies the style accordingly

Hope this helps



来源:https://stackoverflow.com/questions/38657347/change-day-number-color-on-click-not-background

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!