无法使用jquery将类添加到datepicker [英] can't add class with jquery to datepicker

查看:85
本文介绍了无法使用jquery将类添加到datepicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一整天都在努力,终于决定要求帮忙。我有一个日期戳(jquery ui),我用来自google日历的事件填充,并相应地更改类。迄今为止,我使用了datepicker的beforeShowDay功能,效果很好。不幸的是,日历事件是用西班牙语写的,所以我使用另一个函数(以下代码)摆脱了beforeShowDay函数中的所有重音字符:

 code> 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;
};

问题是我无法让IE 11使用此功能。 (它不会替换任何重音字符),所以我决定做的不同,并添加了这一行:

  if( is()()($ td [class * =Highlighted]')not('td [class * =Unknown]' ($(this).attr('class')。replace(/ [áéíóúñäëïöü] / gi,'x'));}); 
}

以前我定义了检查它是否是Internet Explorer 11的功能: / p>

  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))); } 

然而,无论代码中哪里都放置有问题的行(添加类的那个) ,它不会添加任何东西,我知道这可能是因为我在这个地方添加了这个范围可能是错误的地方,所以我尝试从 $(document).ready(function( ){ $(function()无效,我也把这行代码放在几乎任何可以想到的地方,例如在点击事件时,当某些复选框是clicket(它们是负责显示日历中的事件的那些)时触发的点击事件,再次无效,例如,将以下代码段放在以下结尾处是unsuccesfull: / p>

  $('input:checkbox')。live('click',function(){
validaObjeto这个));

//我试过把它放在这里
});

目前我在这里(点击事件调用的函数内部):

  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();
控制台.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(,); (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();
控制台.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);
}
}
}

无效。奇怪的是,如果我在添加课程的代码行之前发出警报,它会显示警报(几乎在每一个放置该行的地方,我现在记得不清楚)。当然,如果我从开发人员的控制台运行这行,那么它会根据应该改变类。



所以我猜这个问题是:¿地球上的那条线应该是它的工作?



或者也许有人可以指出一个原因,以便在Internet Explorer中使用这个功能不起作用?

解决方案

是一个老帖子,但我想告诉我使用这个库的解决方案: phpjs 和功能 utf8_encode utf8_decode 我使IE行为,问题是由于服务器或浏览器的编码,我从来没有想过实际的原因,字符被错误编码(仅在IE中),但是在传递这些函数之前调用这些函数解决了问题。


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. I used the beforeShowDay function of the datepicker with good results so far. 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):

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. (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:

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:

$('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:

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?

解决方案

I know this is an old post, but I wanted to tell the solution I came up to, using this library: phpjs and the functions utf8_encode and utf8_decode I made IE behave, the problem was that due to the encoding of the server, or the browser, I never figured out the actual reason, the characters were being incorrectly encoded (only in IE), but calling those functions before passing them solved the problem.

这篇关于无法使用jquery将类添加到datepicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆