7

我收到一个仅出现在出色的 IE8 上的错误,它指向以下函数,特别是以下行:return (expDate.getTime() > Date.now());

$.validator.addMethod("checkDocExpiry",function(value) {
    var driverLicExp = ($('#drivers-license-expiration').val()) ? $('#drivers-license-expiration').val() : '';
    if (driverLicExp != ''){
        var expDate = new Date(driverLicExp);
        return (expDate.getTime() > Date.now());
    }else{
        return (true);
    }
}, "Your driver's license has expired.");

我不确定是什么原因造成的,我对为旧版浏览器进行开发还很陌生。这在 FF、IE10、Chrome、Safari 中运行良好。

任何帮助将非常感激。

谢谢

4

4 回答 4

10

看起来Date.now()在 IE8 中不支持(请参阅底部的表格):

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now

new Date()应该为您提供具有当前日期的日期对象。

于 2013-08-05T22:02:50.577 回答
7

Shim 使用事实valueOf a Datems ..

if (!Date.now) Date.now = function () {return +new Date();};
于 2013-08-05T22:07:39.950 回答
3

IE 8 不支持 Date.now。将其实现为:

if(!Date.now) { Date.now = function(){ return new Date().getTime();};}
于 2013-08-05T22:48:04.153 回答
0

我的通灵调试技巧告诉我,您使用的是不支持 IE8 的 jQuery 2.0。

您需要使用 1.10。

于 2013-08-05T22:00:56.637 回答