关于bootstrap时间控件datetimepicker的位置错乱问题

 最近遇到datetimepicker这个时间控件在加载到网页显示时会发生错乱,具体解决如下:
1、首先我的源代码是从网站下载的:http://www.bootcss.com/p/bootstrap-datetimepicker/demo.htm
采用的源码是:sample in bootstrap v2文件夹下的:

2、考虑到位置错乱问题应该是在 js文件中,通过查找最终确定在bootstrap-datetimepicker.js中的问题:
    应将其中的place:代码修改如下:
place: function () {
        if (this.isInline) return;

        if (!this.zIndex) {
            var index_highest = 0;
            $('div').each(function () {
                var index_current = parseInt($(this).css("zIndex"), 10);
                if (index_current > index_highest) {
                    index_highest = index_current;
                }
            });
            this.zIndex = index_highest + 10;
        }

        var offset, top, left, containerOffset;
        if (this.container instanceof $) {
            containerOffset = this.container.offset();
        } else {
            containerOffset = $(this.container).offset();
        }

        if (this.component) {
            offset = this.component.offset();
            left = offset.left;
            if (this.pickerPosition == 'bottom-left' || this.pickerPosition == 'top-left') {
                left += this.component.outerWidth() - this.picker.outerWidth();
            }
        } else {
            offset = this.element.offset();
            left = offset.left;
        }

        if(left+220 > document.body.clientWidth){
                    left = document.body.clientWidth-220;
              }

        if (this.pickerPosition == 'top-left' || this.pickerPosition == 'top-right') {
            top = offset.top - this.picker.outerHeight();
        } else {
            top = offset.top + this.height;
        }

        top = top - containerOffset.top;
        left = left - containerOffset.left;

        if(this.container != 'body') top = top + document.body.scrollTop

        this.picker.css({
            top:    top,
            left:   left,
            zIndex: this.zIndex
        });
    },
最后问题解决!!

参考链接:https://github.com/smalot/bootstrap-datetimepicker/issues/363

转载于:https://www.cnblogs.com/ma-lijun/p/5565980.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值