兼容低版本 IE 的 JScript 5.5 实现(2)
2008-02-23 07:55:26来源:互联网 阅读 ()
Date.prototype.toTimeString = function () {
var s = this.toString().split(' ');
return [s[3], s[4]].join(' ');
}
Date.prototype.toLocaleDateString = function () {
return this.toLocaleString().split(' ')[0];
}
Date.prototype.toLocaleTimeString = function () {
return this.toLocaleString().split(' ')[1];
}
String.prototype.toLocaleLowerCase = function () {
return this.toLowerCase();
}
String.prototype.toLocaleUpperCase = function () {
return this.toUpperCase();
}
String.prototype.localeCompare = function (str) {
if (this > str) return 1;
if (this < str) return -1;
return 0;
}
Number.prototype.toExponential = function (n) {
function repeat(s, n) {
var out = "";
for (var i = 0; i < n; i ) {
out = s;
}
return out;
}
if (!n) {
n = 0;
}
else {
n = parseInt(n);
if (n < 0 || n > 20) {
@if (@_jscript_version < 5)
return null;
@else
var e = new Error(-2146823262, "The number of fractional digits is out of range");
e.name = "RangeError";
e.message = e.description;
throw(e);
@end
}
}
var s, d, e, len;
s = this.toString().split("e");
d = parseFloat(s[0]);
e = 0;
if (typeof(s[1]) != "undefined") {
e = parseInt(s[1]);
}
s = d.toString().split(".");
if (typeof(s[1]) != "undefined") {
e = e - s[1].length;
d = s[0] s[1];
d = d.replace(/^0 /g, "");
if (d == "") d = "0";
}
s = d.toString();
len = s.length - 1;
e = len;
if (len < n) {
s = repeat("0", n - len);
}
else if (len > n) {
s = Math.round(parseFloat("." s) * Math.pow(10, n 1)).toString();
if ((s.length - 1) > n) {
e = 1;
s = Math.round(parseFloat("." s) * Math.pow(10, n 1)).toString();
}
}
if (e >= 0) {
e = " " e;
}
if (n == 0) {
return s "e" e;
}
else {
return s.substr(0, 1) "." s.substr(1) "e" e;
}
}
Number.prototype.toFixed = function (n) {
function repeat(s, n) {
var out = "";
for (var i = 0; i < n; i ) {
out = s;
}
return out;
}
if (!n) {
n = 0;
}
else {
n = parseInt(n);
if (n < 0 || n > 20) {
@if (@_jscript_version < 5)
return null;
@else
var e = new Error(-2146823262, "The number of fractional digits is out of range");
e.name = "RangeError";
e.message = e.description;
throw(e);
@end
}
}
var s, d, e, len;
s = this.toString().split("e");
d = parseFloat(s[0]);
e = 0;
if (typeof(s[1]) != "undefined") {
e = parseInt(s[1]);
}
s = d.toString().split(".");
if (typeof(s[1]) != "undefined") {
e = e - s[1].length;
d = s[0] s[1];
d = d.replace(/^0 /g, "");
if (d == "") d = "0";
}
s = d.toString();
len = s.length - 1;
if (e >= 0) {
s = repeat("0", e);
if (n > 0) {
s = "." repeat("0", n);
}
}
else if (-e <= n) {
s = repeat("0", 1 - e - s.length) s;
s = s.substr(0, s.length e) "." s.substr(s.length e) repeat("0", n e);
}
else {
s = repeat("0", 1 - e - s.length) s;
d = parseFloat(s.substr(0, s.length e) "." s.substr(s.length e));
s = Math.round(d * Math.pow(10, n)).toString();
if (n > 0) {
s = repeat("0", n - s.length 1) s;
s = s.substr(0, s.length - n) "." s.substr(s.length - n);
}
}
return s;
}
Number.prototype.toPrecision = function (n) {
function repeat(s, n) {
var out = "";
for (var i = 0; i < n; i ) {
out = s;
}
return out;
}
if (typeof(n) == "undefined") {
return this.toString();
}
else {
n = parseInt(n);
if (n < 1 || n > 21) {
@if (@_jscript_version < 5)
return null;
@else
var e = new Error(-2146823262, "The precision is out of range");
e.name = "RangeError";
e.message = e.description;
throw(e);
@end
}
}
if (this.valueOf() == 0) {
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash
