简体   繁体   English

无法将带有jquery的类添加到datepicker

[英]can't add class with jquery to datepicker

I've been struggling with this all morning and finally I've decided to ask for help. 我整个上午一直在苦苦挣扎,最后我决定寻求帮助。 I have a datepicker (of jquery ui) which I populate with events from google calendar and change the classes accordingly. 我有一个日期选择器(jquery ui),它填充了Google日历中的事件,并相应地更改了类。 I used the beforeShowDay function of the datepicker with good results so far. 到目前为止,我已使用datepicker的beforeShowDay函数,效果良好。 Unfortunately, the calendar events are written in spanish, so I got rid of all the accented characters in the beforeShowDay function using another function (following code): 不幸的是,日历事件是用西班牙语编写的,因此我使用另一个函数(以下代码)摆脱了beforeShowDay函数中的所有重音字符:

function accentsTidy(s){
    var r = s.toLowerCase();
     non_asciis = {'a': '[àáâãäå]', 'ae': 'æ', 'c': 'ç', 'e': '[èéêë]', 'i': '[ìíîï]', 'n': 'ñ', 'o': '[òóôõö]', 'oe': 'œ', 'u': '[ùúûűü]', 'y': '[ýÿ]'};
    for (i in non_asciis) { r = r.replace(new RegExp(non_asciis[i], 'g'), i); }
    return r;
};

The problem is I can't get IE 11 to work with this function. 问题是我无法让IE 11使用此功能。 (It doesn't replace any of the accented characters) so I decided to do it differently and added this line: (它不会替换任何带重音符号的字符),所以我决定以不同的方式做,并添加了以下这一行:

if (isIE) {
                        $('td[class*="Highlighted"]').not('td[class*="Unknown"]').each(function (index) { $(this).addClass($(this).attr('class').replace(/[áéíóúñäëïöü]/gi, 'x')); });
                    }

and previously I defined the function to check if it is Internet Explorer 11: 之前我定义了用于检查它是否为Internet Explorer 11的函数:

function isIE() { return ((navigator.appName == 'Microsoft Internet Explorer') || ((navigator.appName == 'Netscape') && (new RegExp("Trident/.*rv:([0-9]{1,}[\.0-9]{0,})").exec(navigator.userAgent) != null))); }

However no matter where in the code I place the line in question (the one that adds the classes, it doesn't add anything. I know it may be because I'm adding that line somewhere where the scope may be wrong, so I've tried changing from $(document).ready(function(){ to $(function() to no avail. I've also placed that line of code almost anywhere I can think of, for example in the click event that is fired when some checkboxes are clicket (which are the ones responsible of showing the events in the calendar), again to no avail, for example, putting that line of code at the end of the following was unsuccesfull: 但是,无论在代码中的什么地方,我都将行放在有问题的位置(添加类的行,它不会添加任何内容。我知道这可能是因为我是在范围可能有误的地方添加了该行,所以我'尝试将$(document).ready(function(){更改$(function()无济于事。我还将代码行放在几乎我能想到的任何位置,例如在click事件中单击某些复选框(负责在日历中显示事件的复选框)时触发,同样无济于事,例如,将代码行放在下面的末尾是不完整的:

$('input:checkbox').live('click', function () {
        validaObjeto($(this));

//I've tried putting it here
    });

Currently I have it in here (inside the function that is called on the click event: 目前,我在这里(在click事件中调用的函数内部)中有它:

function validaObjeto(elem){
    if (elem.val() != "semestre") {
        if (elem.val().indexOf(",") == -1) {
            var identificador = $(elem).val();
            var request = gapi.client.calendar.events.get({ 'calendarId': 'cide.edu_sm151i2pdhu2371vq8hamcver4@group.calendar.google.com', 'eventId': identificador });
            request.execute(function (resp) {
                var dateIni = new Date(resp.start.date);
                var dateFin = new Date(resp.end.date);
                diasperiodo = dateFin.getDate() - dateIni.getDate();
                for (i = 0; i <= diasperiodo; i++) {
                    datekey = new Date();
                    console.log(new Date(datekey.setTime(dateIni.getTime() + i * 86400000)));
                    if ($(elem).is(":checked")) {
                        todosEventos[$.datepicker.formatDate('yy-mm-dd', new Date(datekey.setTime(dateIni.getTime() + i * 86400000)))] = { 'summary': resp.summary, 'start': new Date(resp.start.date), 'end': new Date(resp.end.date) };
                    }
                    else {
                        delete todosEventos[$.datepicker.formatDate('yy-mm-dd', new Date(datekey.setTime(dateIni.getTime() + i * 86400000)))];
                    }
                }
                $('#cal').datepicker("refresh");
                if (isIE) {
                    $('td[class*="Highlighted"]').not('td[class*="Unknown"]').each(function (index) { $(this).addClass($(this).attr('class').replace(/[áéíóúñäëïöü]/gi, 'x')); });
                }
            });
        }
        else {
            evts = $(elem).val().split(",");
            for (i = 0; i < evts.length; i++) {
                var identificador = evts[i];
                var request = gapi.client.calendar.events.get({ 'calendarId': 'cide.edu_sm151i2pdhu2371vq8hamcver4@group.calendar.google.com', 'eventId': identificador });
                request.execute(function (resp) {
                    var dateIni = new Date(resp.start.date);
                    var dateFin = new Date(resp.end.date);
                    diasperiodo = dateFin.getDate() - dateIni.getDate();
                    for (i = 0; i <= diasperiodo; i++) {
                        datekey = new Date();
                        console.log(new Date(datekey.setTime(dateIni.getTime() + i * 86400000)));
                        if ($(elem).is(":checked")) {
                            todosEventos[$.datepicker.formatDate('yy-mm-dd', new Date(datekey.setTime(dateIni.getTime() + i * 86400000)))] = { 'summary': resp.summary, 'start': new Date(resp.start.date), 'end': new Date(resp.end.date) };
                        }
                        else {
                            delete todosEventos[$.datepicker.formatDate('yy-mm-dd', new Date(datekey.setTime(dateIni.getTime() + i * 86400000)))];
                        }
                    }
                    $('#cal').datepicker("refresh");
                    if (isIE) {
                        $('td[class*="Highlighted"]').not('td[class*="Unknown"]').each(function (index) { $(this).addClass($(this).attr('class').replace(/[áéíóúñäëïöü]/gi, 'x')); });
                    }
                    });
            }
        }
    }
    else {
        if ($(elem).is(":checked")) {
            var inicioDeClases, finDeClases;
            var request = gapi.client.calendar.events.get({ 'calendarId': 'cide.edu_sm151i2pdhu2371vq8hamcver4@group.calendar.google.com', 'eventId': 'hhq29qmmaeql9ne810q3s0pips' });
            request.execute(function (resp) {
                inicioDeClases = new Date(resp.start.date);
            });
            var peticion = gapi.client.calendar.events.get({ 'calendarId': 'cide.edu_sm151i2pdhu2371vq8hamcver4@group.calendar.google.com', 'eventId': '52p6lv5qgmal7t1ibb2u3rbn84' });
            peticion.execute(function (resp) {
                finDeClases = new Date(resp.end.date);
                unEvento = { 'summary': 'Semestre de clases', 'start': inicioDeClases, 'end': finDeClases };
                $('#cal').datepicker("refresh");
            });
        }
        else {
            unEvento = null;
            $('#cal').datepicker("refresh");
        }
    }
}

To no avail. 无济于事。 Strange thing is if I place an alert before the line of code that is supposed to add the class, it shows the alert (almost in every place where I've put that line, I can't remember exactly where right now). 奇怪的是,如果我在应该添加该类的代码行之前放置一个警报,它将显示警报(几乎在我放置该行的每个位置,我现在都不记得确切的位置)。 And of course if I run the line from the developer's console, it does change the classes as it is supposed to. 当然,如果我从开发人员控制台运行该行,它确实会按预期更改类。

So I guess the question is: ¿where on earth is that line supposed to be for it to work? 所以我想问题是:¿那条线应该在哪里运行?

Or maybe someone can point out a reason why the accentsTidy function doesn't work in Internet Explorer? 也许有人可以指出accentsTidy函数在Internet Explorer中不起作用的原因?

我知道这是一篇旧文章,但是我想使用这个库告诉我解决的方法: phpjsutf8_encodeutf8_decode函数使IE表现正常,问题是由于服务器的编码或浏览器,我从来没有弄清楚实际原因,这些字符编码不正确(仅在IE中),但是在传递这些函数之前调用了这些函数可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM