Twitter Bootstrap Datepicker within modal window

后端 未结 22 1864
旧时难觅i
旧时难觅i 2020-11-29 02:42

I am currently using the Twitter Bootstrap framework, and when using the modal windows I cannot get over js elements to work like datepicker or validation, though chosen and

22条回答
  •  南笙
    南笙 (楼主)
    2020-11-29 03:07

    This solutions worked perfectly for me to render the datepicker on top of bootstrap modal.

    http://jsfiddle.net/cmpgtuwy/654/

    HTML


    Some content goes here
    Some more content.

    Javascript

    $('#dtp').datetimepicker({
    format: 'MMM D, YYYY',
    widgetParent: 'body'});
    
    
    $('#dtp').on('dp.show', function() {
          var datepicker = $('body').find('.bootstrap-datetimepicker-widget:last');
          if (datepicker.hasClass('bottom')) {
            var top = $(this).offset().top + $(this).outerHeight();
            var left = $(this).offset().left;
            datepicker.css({
              'top': top + 'px',
              'bottom': 'auto',
              'left': left + 'px'
            });
          }
          else if (datepicker.hasClass('top')) {
            var top = $(this).offset().top - datepicker.outerHeight();
            var left = $(this).offset().left;
            datepicker.css({
              'top': top + 'px',
              'bottom': 'auto',
              'left': left + 'px'
            });
          }
        });
    

    CSS

    .wrapper {
    height: 100px;
    overflow: auto;}
    body {
    position: relative;
    }
    

提交回复
热议问题