Bootstrap is now a very popular framework for responsive layouts that can help us quickly build Web applications, using the date-time selection control (DateTimePicker) when using bootstrap, which is used by itself, And not too much attention to compatibility issues, today's whim, with the IE8 test, my God, incredibly can not use, then the Internet search, see if there is a similar problem, not to mention, a lot of search, when I read a few, I do not want to continue to see, the same article, you understand, And still can not solve my problem, do not know just because of the version of the problem, I now use to provide the official online version of the latest.
The problem I see on the web is basically that the Bootstrap-datetimepicker.js script doesn't support the indexof () method, so the solution is to add code like the following in the script:
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 (
this[from) = = ELT) return from
;
return-1;
But I saw in the Bootstrap-datetimepicker.js file that the author had fixed the problem, and there was a picture of the truth:
So it is not the cause of this, ultimately helpless, or honest debugging bar. Tools can be used ietester, but today I found IE new version of the developer tool is very useful, you can directly switch the IE version of the test, open the developer tool and replaced by IE8.
Then refresh the page and watch the console information
We can be delighted to find that there is an error in the Timezoneabbreviation function, and here we already know the problem is that Ref.slice (0,-1) is wrong, because ref is undefined or null, I believe many people will have the same doubts as I do, Before we've judged NULL, how could it be wrong, we can go on and look at date = (new Date ()). ToString (); What exactly is the value of date after execution, through the console, we can easily monitor the value of the channel specific
Add a breakpoint at this place, switch IE version, change it to edge, is also the latest version, refresh the page to observe again.
We can see that the results are not the same two times, this will explain why the IE8 error occurs because converting the date to a string does not include the (Chinese Standard Time) part, so the value of Date.split (' (') [1] is undefined, that is, the value of ref is undefined, Therefore, when invoking the slice method, there is an error, the solution is simple, we only need to modify the logic of judgment, the sentence can be modified to the following form:
Formattedstr = (ref = Date.split (' (') [1])? ref.slice (0,-1): 0) | | date.split (");
In this way, in the IE8 can also be normal operation.