js Number类型 NaN和Infinity UEditor上传图片进度条有可能显示Infinity的问题

分类:Javascript| 发布:佚名| 查看: | 发表时间:2014/7/11

js在计算数值时有2个值比较特殊,分别是:NaN 和 Infinity (-Infinity)

Parsing something that isn't a number results in NaN. isNaN helps to detect those cases:

parseInt("hello", 10) // NaN
isNaN(parseInt("hello", 10)) // true

Division through zero results in Infinity:

1 / 0 // Infinity

Both NaN and Infinity are of type "number":

typeof NaN // "number"
typeof Infinity // "number"

Note that NaN compares in a strange way:

NaN == NaN // false (!)

But:

Infinity == Infinity // true


在UEditor里有个问题,上传图片(大图)的时候,进度条的百分比数比如:30%..90%..100%。有可能会变成:Infinity 。
如图:UEditor图片上传进度条 郑州网建

对应的文件地址:http://camnpr.com/ueditor/dialogs/image/image.js Line 551  修改一行代码,如下:

percent = total ? loaded / total : 0;
spans.eq(0).text(Math.round((percent == Infinity ? 1 : percent) * 100) + '%');// 修改此行
spans.eq(1).css('width', Math.round(percent * 100) + '%');
365据说看到好文章不转的人,服务器容易宕机
原创文章如转载,请注明:转载自郑州网建-前端开发 http://camnpr.com/
本文链接:http://camnpr.com/javascript/1458.html