IE6-8中Date不支持toISOString的修復方法
更新時間:2014年05月04日 09:40:29 作者:
這篇文章主要介紹了IE6-8中Date不支持toISOString的修復方法,需要的朋友可以參考下
Date.prototype.toISOString方法是在ES5里添加的,ES3文檔中沒有,如下
這個方法在IE6/7/8中不支持,可按下面方式修復下
if (!Date.prototype.toISOString) {
Date.prototype.toISOString = function() {
function pad(n) { return n < 10 ? '0' + n : n }
return this.getUTCFullYear() + '-'
+ pad(this.getUTCMonth() + 1) + '-'
+ pad(this.getUTCDate()) + 'T'
+ pad(this.getUTCHours()) + ':'
+ pad(this.getUTCMinutes()) + ':'
+ pad(this.getUTCSeconds()) + '.'
+ pad(this.getUTCMilliseconds()) + 'Z';
}
}
相關:
http://msdn.microsoft.com/zh-cn/library/ie/ff925953%28v=vs.94%29.aspx
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
這個方法在IE6/7/8中不支持,可按下面方式修復下
復制代碼 代碼如下:
if (!Date.prototype.toISOString) {
Date.prototype.toISOString = function() {
function pad(n) { return n < 10 ? '0' + n : n }
return this.getUTCFullYear() + '-'
+ pad(this.getUTCMonth() + 1) + '-'
+ pad(this.getUTCDate()) + 'T'
+ pad(this.getUTCHours()) + ':'
+ pad(this.getUTCMinutes()) + ':'
+ pad(this.getUTCSeconds()) + '.'
+ pad(this.getUTCMilliseconds()) + 'Z';
}
}
相關:
http://msdn.microsoft.com/zh-cn/library/ie/ff925953%28v=vs.94%29.aspx
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
相關文章
Bootstrap treeview實現動態(tài)加載數據并添加快捷搜索功能
本文實現了運用bootstrap treeview實現動態(tài)加載數據,并且添加快捷搜索功能,需要的朋友參考下2018-01-01

