Home  >  Article  >  php教程  >  Bootstap datetimepicker报错TypeError: intermediate value

Bootstap datetimepicker报错TypeError: intermediate value

WBOY
WBOYOriginal
2016-06-13 08:39:041372browse

Bootstap datetimepicker报错TypeError: intermediate value

Bootstrap datetimepicker有多个版本,官方的链接中,只是datepicker,没有时间的选择,原版的datetimepicker也不再更新,不能用新版的jquery。
现在https://github.com/Eonasdan/bootstrap-datetimepicker这个版本最完善,但是一大堆依赖很头疼;
https://github.com/smalot/bootstrap-datetimepicker还不错,比较轻巧,但是用起来报错。

报错:

  1. TypeError: (intermediate value).toString(...).split(...)[1] is undefined


  2. ...d"?false:k.title;this.defaultTimeZone=(new Date()).toString().split("(

原文:

  1. this.defaultTimeZone=(new Date()).toString().split("(")[1].slice(0,-1);
意思为:先取得Date对象,然后再字符串化,再用(来分隔字符串,然后取其中的第二个,再从右向左取第一项,也就是取时区项。
但在Firefox中,字符串化的结果为:“Wed May 25 2016 16:07:14 GMT+0800”,没有括号,导致错误。

更为通用的,时区可以用getTimezoneOffset()来获取,这个结果的单位是分钟,所以要除以60才可以:
修改为:
  1. this.defaultTimeZone='GMT '+(new Date()).getTimezoneOffset()/60

修改后就可以正常使用了。



另外还有一个字体错误,如果使用了fa字体,则会报错,系统中会检测不到fontAwesome,所以可以直接赋这个变量为true:

  1. this.fontAwesome=k.fontAwesome||this.element.data("font-awesome")||false;
改为:
  1. this.fontAwesome=true



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn