引导datetimepicker控件位置异常的解决方法

  

今天在写毕设的时候,用到了bootstrap-datetimepicker作为日期控件。

  

在git上克隆下最新的代码,运行演示,发现控件区域整体下移1000 px左右。

  

作为一个准备拿来就用的后台程序猿,此刻我的内心是崩溃的…

  

百度了很久,没有找到对应的解决方案,于是自己动手去源码修改。

  

最终解决方案:

  

打开源码,的bootstrap-datetimepicker.js文件

  

行527行,打开这一段注释即可

     /*如果(这一点。pickerPosition==弊笊系摹皘 |。pickerPosition==坝疑系摹?{=抵消。前this.picker.outerHeight ();   其他}{=抵消。前+ this.height;   } */之前      

如果看着还是不是很舒服的话,建议注释掉线533 - 544

     =最高- containerOffset。+ 169;   左=左——containerOffset。+ 210,      

为什么要这样解决呢?

        地方:函数(){   如果(this.isInline)返回;      如果(! this.zIndex) {   var index_highest=0;   $ (' div ')。每个(函数(){   var index_current=方法($ (). css (“zIndex”), 10);   如果(index_current比;index_highest) {   index_highest=index_current;   }   });   这一点。zIndex=index_highest + 10;   }      var抵消,上,左,containerOffset;   如果这一点。容器instanceof美元){   containerOffset=this.container.offset ();   其他}{   containerOffset=$ (this.container) .offset ();   }      如果(this.component) {   抵消=this.component.offset ();   左=offset.left;   如果这一点。pickerPosition==白笙隆眧 |。pickerPosition==白笊系摹?{   左+=this.component.outerWidth ()——this.picker.outerWidth ();   }   其他}{   抵消=this.element.offset ();   左=offset.left;   }      var bodyWidth=document.body。clientWidth | | window.innerWidth;   如果(左+ 220比;bodyWidth) {   左=bodyWidth - 220;   }/*如果(这一点。pickerPosition==弊笊系摹皘 |。pickerPosition==坝疑系摹?{=抵消。前this.picker.outerHeight ();   其他}{=抵消。前+ this.height;   } */=最高- containerOffset。+ 169;   左=左——containerOffset。左+ 210;      this.picker.css ({   上图:,   左:左,   zIndex: this.zIndex   });   },      之前      

上面就是相关的源码,可以看的到,注释了第527行行之后,在后面引用了一个未初始化过的顶级变量

  

嗯…这是一个没经过测试就提交的小错误…

  

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
  

引导datetimepicker控件位置异常的解决方法