bootstrap datetimepicker 日期插件在火狐下出现一条报
网络编程 2021-07-04 19:20www.168986.cn编程入门
日期插件 bootstrap-datetimepicker 在火狐下出现一条报错信息:TypeError: (intermediate value).toString(…).split(…)[1] is undefined.什么原因导致的呢,狼蚁网站SEO优化长沙网络推广给大家分享解决思路,需要的朋友参考下
日期插件 bootstrap-datetimepicker 在火狐下出现一条报错信息:TypeError: (intermediate value).toString(…).split(…)[1] is undefined
这条错误必然出现,难道没有在 Firefox 下进行测试。
在 Firefox 下查看项目 demo ()可以正常运行,但这个 demo.php 使用的是 2013-3-2 的 datetimepicker,github 项目()已经发布到 2017-3-3,这个最新的版本(以及最近的一些版本)在 Firefox 下测试不完善,计算 defaultTimeZone 时虽然没有出错,但给出的结果也不正确。
源代码如下,运行环境 Firefox 51.0.1(32位)
this.defaultTimeZone = (new Date).toString().split('(')[1].slice(0, -1); this.timezone = options.timezone || this.defaultTimeZone; // 2.4.4 改进版本 this.timezone = options.timezone || timeZoneAbbreviation(); function timeZoneAbbreviation() { var abbreviation, date, formattedStr, i, len, matchedStrings, ref, str; date = (new Date()).toString(); formattedStr = ((ref = date.split('(')[1]) != null ? ref.slice(0, -1) : 0) || date.split(' '); if (formattedStr instanceof Array) { matchedStrings = []; for (var i = 0, len = formattedStr.length; i < len; i++) { str = formattedStr[i]; if ((abbreviation = (ref = str.match(/\b[A-Z]+\b/)) !== null) ? ref[0] : 0) { matchedStrings.push(abbreviation); } } formattedStr = matchedStrings.pop(); } return formattedStr; }
出错原因是 Firefox 下 Date.prototype.toString 返回结果不包含 TimeZone 的文字描述。
2.4.4 改进版本使用的 timeZoneAbbreviation 函数在 Firefox 下返回 true
对 timeZoneAbbreviation 使用的三元表达式依次简化
((abbreviation = (ref = str.match(/\b[A-Z]+\b/)) !== null) ? ref[0] : 0) (abbreviation = (ref = str.match(/\b[A-Z]+\b/)) !== null) (abbreviation = (xxx) !== null) (abbreviation = xxx !== null) abbreviation 必然是布尔值,如果将 matchedStrings.push(abbreviation) 换成 matchedStrings.push(str) 更接近预期值。
推荐使用文末的方案。
解决方案
将 date toString 最后一个空格之后的字符串作为 TimeZone。
// this.defaultTimeZone = (new Date).toString().split('(')[1].slice(0, -1); this.defaultTimeZone = (new Date + '').split(' ').slice(-1)[0].replace(/\(|\)/g, ''); this.timezone = options.timezone || this.defaultTimeZone;
以上所述是长沙网络推广给大家介绍的 bootstrap datetimepicker 日期插件在火狐下出现一条报错信息的原因分析及解决办法,希望对大家有所帮助,如果大家有任何疑问请给我留言,长沙网络推广会及时回复大家的。在此也非常感谢大家对狼蚁SEO网站的支持!
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程