简体   繁体   English

日期选择器:显示从下一个/上一个月开始的天数(如果在当前一个月的结束/开始一周中)

[英]Datepicker: Show days from next/prev month (if in ending/starting week of current one)

This is how datepicker shows a month by default, numbers start the first of the month and end the last of the month: 这是日期选择器默认情况下显示月份的方式,数字从该月的第一天开始到该月的最后一天结束:

在此处输入图片说明

The thing is that I need to fill the whole calendar with numbers, like this: 问题是我需要用数字填充整个日历,如下所示:

在此处输入图片说明

So I found that the option showOtherMonths to true does the trick: 因此,我发现将showOtherMonthstrue可以解决问题:

在此处输入图片说明

But if you notice, it adds an extra week, Wich I dont need, 但是,如果您注意到,它又增加了一个星期,我不需要,

Any idea why? 知道为什么吗?

-EDIT- -编辑-

The whole code: 整个代码:

jQuery('.datepicker').each(function (i) {
    var $item = jQuery(this);
    var fechas = $item.data('fechas') != '' ? $item.data('fechas') : '';    
    var urls = $item.data('urls') != '' ? $item.data('urls') : '';
    var tipos = $item.data('tipos') != '' ? $item.data('tipos') : '';
    var titulos = $item.data('titulos') != '' ? $item.data('titulos') : '';
    var options = {
        'dateFormat' : dateFormat,
        'display' : $item.data('display') == '' ? '' : $item.data('display'),
        firstDay: 1,
        numberOfMonths: $item.data('months') == '' ? 1 : $item.data('months'),
        showOtherMonths: true,
        selectOtherMonths: false
    }
    /* Marcar los dias con sesion */
    if (fechas.length) {
        options.beforeShowDay = function(datestr) {
            var fecha = jQuery.datepicker.formatDate( dateFormat, datestr);
            var arr = [true, ''];
            for( var j = 0 ; j < fechas.length ; j++ ) {  
                if ( fecha == fechas[j] ) {
                    return [true, 'dia-con-evento '+tipos[j], titulos[j], 'link'];
                } 
            }
            return arr;
        }
    }       
    /* Agregar links a los días */
    options.onSelect = function (datestr) {
        if ( fechas.indexOf(datestr) != -1 ) {
            location.href =  urls[ fechas.indexOf(datestr) ];                   
        }
    }   
    $item.datepicker( options );
});

Markup: 标记:

<div class="datepicker year" 
             data-display="inline"
             data-fechas='["13\/05\/2015","11\/02\/2015","11\/03\/2015","10\/06\/2015","08\/04\/2015","08\/07\/2015","30\/03\/2015","30\/03\/2015","04\/05\/2015","04\/05\/2015","14\/05\/2015","24\/05\/2015","03\/06\/2015","18\/06\/2015","28\/06\/2015","03\/06\/2015","03\/06\/2015","13\/06\/2015","07\/07\/2015","08\/07\/2015","09\/07\/2015","07\/08\/2015","17\/08\/2015","15\/11\/2015"]'
             data-urls='["\/sescam-la-ventana\/?q=sesion\/1","\/sescam-la-ventana\/?q=sesion\/2","\/sescam-la-ventana\/?q=sesion\/3","\/sescam-la-ventana\/?q=sesion\/4","\/sescam-la-ventana\/?q=sesion\/5","\/sescam-la-ventana\/?q=caso\/6","\/sescam-la-ventana\/?q=caso\/6","\/sescam-la-ventana\/?q=caso\/6","\/sescam-la-ventana\/?q=caso\/6","\/sescam-la-ventana\/?q=caso\/6","\/sescam-la-ventana\/?q=caso\/6","\/sescam-la-ventana\/?q=caso\/6","\/sescam-la-ventana\/?q=caso\/6","\/sescam-la-ventana\/?q=caso\/6","\/sescam-la-ventana\/?q=caso\/6","\/sescam-la-ventana\/?q=caso\/6","\/sescam-la-ventana\/?q=caso\/6","\/sescam-la-ventana\/?q=caso\/6","\/sescam-la-ventana\/?q=caso\/6","\/sescam-la-ventana\/?q=caso\/6","\/sescam-la-ventana\/?q=caso\/6","\/sescam-la-ventana\/?q=caso\/6","\/sescam-la-ventana\/?q=caso\/6","\/sescam-la-ventana\/?q=caso\/6"]'
             data-tipos='["caso","caso","caso","caso","caso","caso","hito","hito","hito","hito","hito","hito","hito","hito","hito","hito","hito","hito","hito","hito","hito","hito","hito","hito"]'
             data-titulos='["El tratamiento del asma: \"a la carta\" vs \"menu\u0301 del di\u0301a","El caso del Sr. Minotaruro en el laberinto de los ARA II","A vueltas con el protector...","El humor es como el colesterol, unos tienen del bueno, otros del malo","Deprescripcio\u0301n: En busca de la cordura","Mesa redonda BBPP Premio 1a edicio\u0301n","Programaci\u00f3n del caso en La Ventana","Preparaci\u00f3n del materia","Preparaci\u00f3n del materia","Entrega del material","Aprobaci\u00f3n del material y lanzamiento de la sesi\u00f3n cl\u00ednica","Reuni\u00f3n de preproducci\u00f3n","Grabaci\u00f3n","Validaci\u00f3n del v\u00eddeo","Validaci\u00f3n del v\u00eddeo","Publicaci\u00f3n de material en la plataforma de eformaci\u00f3n","Validaci\u00f3n del material en la plataforma de eformaci\u00f3n","Validaci\u00f3n del material en la plataforma de eformaci\u00f3n","Publicaci\u00f3n de v\u00eddeo en web y plataforma","Emisi\u00f3n de la sesi\u00f3n cl\u00ednica","Apertura m\u00f3dulos eformaci\u00f3n","Finalizaci\u00f3n del curso","Presentaci\u00f3n de alumnos aprobados","Pago a ponente"]'  
             data-months='6'
        >
        </div>

DEMO: FIDDLE 演示: FIDDLE

Try this: 尝试这个:

$( "#datepicker" ).datepicker({
    showOtherMonths: true,
    selectOtherMonths: true
});

Please show more of your code, to give you a more in depth answer. 请显示更多代码,为您提供更深入的答案。

Everything seems to be running fine. 一切似乎运行良好。 If the problem persists, i would assume is a different type of script or CSS conflicting with what you have already, perhaps an outdated jquery library. 如果问题仍然存在,我会认为是另一种脚本或CSS与您已有的内容冲突,也许是过时的jquery库。

 $('.datepicker').each(function (i) { var $item = $(this); var fechas = $item.data('fechas') != '' ? $item.data('fechas') : ''; var urls = $item.data('urls') != '' ? $item.data('urls') : ''; var tipos = $item.data('tipos') != '' ? $item.data('tipos') : ''; var titulos = $item.data('titulos') != '' ? $item.data('titulos') : ''; var options = { 'dateFormat' : "dd/mm/yyyy", 'display' : $item.data('display') == '' ? '' : $item.data('display'), firstDay: 1, numberOfMonths: $item.data('months') == '' ? 1 : $item.data('months'), showOtherMonths: true, selectOtherMonths: false } /* Marcar los dias con sesion */ if (fechas.length) { options.beforeShowDay = function(datestr) { var fecha = $.datepicker.formatDate("dd/mm/yyyy", datestr); var arr = [true, '']; for( var j = 0 ; j < fechas.length ; j++ ) { if ( fecha == fechas[j] ) { return [true, 'dia-con-evento '+tipos[j], titulos[j], 'link']; } } return arr; } } /* Agregar links a los días */ options.onSelect = function (datestr) { if ( fechas.indexOf(datestr) != -1 ) { location.href = urls[ fechas.indexOf(datestr) ]; } } $item.datepicker( options ); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <link href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" rel="stylesheet"/> <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script> <div class="datepicker year" data-display="inline" data-fechas='["13\\/05\\/2015","11\\/02\\/2015","11\\/03\\/2015","10\\/06\\/2015","08\\/04\\/2015","08\\/07\\/2015","30\\/03\\/2015","30\\/03\\/2015","04\\/05\\/2015","04\\/05\\/2015","14\\/05\\/2015","24\\/05\\/2015","03\\/06\\/2015","18\\/06\\/2015","28\\/06\\/2015","03\\/06\\/2015","03\\/06\\/2015","13\\/06\\/2015","07\\/07\\/2015","08\\/07\\/2015","09\\/07\\/2015","07\\/08\\/2015","17\\/08\\/2015","15\\/11\\/2015"]' data-urls='["\\/sescam-la-ventana\\/?q=sesion\\/1","\\/sescam-la-ventana\\/?q=sesion\\/2","\\/sescam-la-ventana\\/?q=sesion\\/3","\\/sescam-la-ventana\\/?q=sesion\\/4","\\/sescam-la-ventana\\/?q=sesion\\/5","\\/sescam-la-ventana\\/?q=caso\\/6","\\/sescam-la-ventana\\/?q=caso\\/6","\\/sescam-la-ventana\\/?q=caso\\/6","\\/sescam-la-ventana\\/?q=caso\\/6","\\/sescam-la-ventana\\/?q=caso\\/6","\\/sescam-la-ventana\\/?q=caso\\/6","\\/sescam-la-ventana\\/?q=caso\\/6","\\/sescam-la-ventana\\/?q=caso\\/6","\\/sescam-la-ventana\\/?q=caso\\/6","\\/sescam-la-ventana\\/?q=caso\\/6","\\/sescam-la-ventana\\/?q=caso\\/6","\\/sescam-la-ventana\\/?q=caso\\/6","\\/sescam-la-ventana\\/?q=caso\\/6","\\/sescam-la-ventana\\/?q=caso\\/6","\\/sescam-la-ventana\\/?q=caso\\/6","\\/sescam-la-ventana\\/?q=caso\\/6","\\/sescam-la-ventana\\/?q=caso\\/6","\\/sescam-la-ventana\\/?q=caso\\/6","\\/sescam-la-ventana\\/?q=caso\\/6"]' data-tipos='["caso","caso","caso","caso","caso","caso","hito","hito","hito","hito","hito","hito","hito","hito","hito","hito","hito","hito","hito","hito","hito","hito","hito","hito"]' data-titulos='["El tratamiento del asma: \\"a la carta\\" vs \\"menu\́ del di\́a","El caso del Sr. Minotaruro en el laberinto de los ARA II","A vueltas con el protector...","El humor es como el colesterol, unos tienen del bueno, otros del malo","Deprescripcio\́n: En busca de la cordura","Mesa redonda BBPP Premio 1a edicio\́n","Programaci\ón del caso en La Ventana","Preparaci\ón del materia","Preparaci\ón del materia","Entrega del material","Aprobaci\ón del material y lanzamiento de la sesi\ón cl\ínica","Reuni\ón de preproducci\ón","Grabaci\ón","Validaci\ón del v\ídeo","Validaci\ón del v\ídeo","Publicaci\ón de material en la plataforma de eformaci\ón","Validaci\ón del material en la plataforma de eformaci\ón","Validaci\ón del material en la plataforma de eformaci\ón","Publicaci\ón de v\ídeo en web y plataforma","Emisi\ón de la sesi\ón cl\ínica","Apertura m\ódulos eformaci\ón","Finalizaci\ón del curso","Presentaci\ón de alumnos aprobados","Pago a ponente"]' data-months='6' > </div> 

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

相关问题 jQuery Datepicker从当前月份删除上个月或下个月的日期 - Jquery Datepicker remove days of previous or next month from the current month JQuery UI datepicker如何显示月导航的下一个上一个箭头? - JQuery UI datepicker how to show next prev arrows for month navigation? 在当前月份的引导日期选择器上禁用prev按钮 - disable prev button on current month bootstrap datepicker 日历:从本周开始显示截至下一周的日期 - Calender: Show dates upto next 1 week from current week 如何在js中的日期间隔中获取每个月的开始和结束日期 - How to get starting and ending days of each month in a date interval in js Moment JS(“必须显示下周的几天”) - Moment JS (“Must to show days in next week”) 图表以周间隔显示当月数据 - HIghchart show current month data with week interval 使用Javascript AngularJS从当前日期开始显示未来365天 - show next 365 days from current day using Javascript AngularJS 从今天开始获取星期几 - Get the days of the week starting from today fullcalendar:我怎样才能获得相关查看月份的第一天和最后一天(而不是上一个\\下个月的天) - fullcalendar: how can i get the first and last day of the relevant viewed month (and not the days of of the prev \ next month)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM