Bootstrap Datetimepicker 兼容IE8

bootstrap datetimepicker插件在IE8下显示无效,报错提示bootstrap-datetimepicker.js脚本不支持indexOf()方法

解决方案:在bootstrap-datetimepicker.js/bootstrap-datetimepicker.min.js最前面添加以下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
if (!Array.prototype.indexOf)  
{
Array.prototype.indexOf = function(elt /*, from*/)
{
var len = this.length >>> 0;

var from = Number(arguments[1]) || 0;
from = (from < 0) ? Math.ceil(from) : Math.floor(from);
if (from < 0)
from += len;
for (; from < len; from++)
{
if (from in this &&
this[from] === elt)
return from;
}
return -1;
};
}
Author

Ludis

Posted on

2015-08-19

Updated on

2016-07-22

Licensed under

Comments