保持活动的颜色变化

时间:2016-03-31 16:28:17

标签: javascript jquery fullcalendar

我想在用户点击它时更改颜色的事件 我目前正在使用以下代码来更改边框和文本颜色,它工作正常:

eventClick: function(calEvent, jsEvent, view) {
    userClicked (calEvent.start); //used elsewhere, not important to this question
    $(this).css('border-color', 'red'); //shows user what they have clicked
    $(this).css('color', 'red'); //shows user what they have clicked
}//event click

我只向用户显示月份视图 这有效,直到用户使用箭头按钮更改月份,一旦点击,更改的颜色消失,事件再次具有原始颜色。

我想永久更改颜色,除非用户刷新页面 如何保持事件颜色与我更改的颜色相同?

由于

1 个答案:

答案 0 :(得分:1)

您获得borderColor作为第一个参数,除了使用jQuery设置css之外,您还必须编辑事件的backgroundColoreventClick: function(calEvent, jsEvent, view) { userClicked (calEvent.start); //used elsewhere, not important to this question $(this).css('border-color', 'red'); //shows user what they have clicked $(this).css('color', 'red'); //shows user what they have clicked calEvent.backgroundColor = 'red'; calEvent.borderColor = 'red'; }//event click 属性,如下所示:

var lang = getLangCookie('lang');
console.log('lang = ', lang);
$.ajax({
    type: "GET",
    url: '/menu.xml',
    dataType: "xml",
    success: function (xml) {
        $(xml).find('description ' + lang).each(function () {
            $(this).parent().html($(this).html());
        }
        );
        var menu = [];
        var data = $.xml2json(xml)['#document'];
        that.menu = data.menu;
        console.log('menu = ', that.menu);
    }
}

);
function getLangCookie(lang) {
    var name = lang + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1);
        if (c.indexOf(name) == 0) {
            return c.substring(name.length, c.length);
        }
    }
    return "";
}
// by clicking on English button set the cookie value
function onEnglishbtn() {
    setLangCookie("lang", "en", 30);

    document.location.reload();
    var lang = getLangCookie('lang');

    return lang;
}

    function setLangCookie(lang, value, exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
    var expires = "expires=" + d.toGMTString();
    document.cookie = lang + "=" + value + "; " + expires;
}
// function onload from index.html setting up the lang by default
window.onload = function () {
    setLangCookie("lang", "de", 30);
    if (typeof window.localStorage !== "undefined" && !localStorage.getItem('visited')) {
        localStorage.setItem('visited', true);
        setLangCookie("lang", "de", 30);
    }
}