1. 程式人生 > >JS 小腳本匯聚

JS 小腳本匯聚

展示 left black size bytes AC return 文件大小 根據

  1. 根據文件length展示文件大小

    if (bytes === 0) 
    

    
    							return ‘0 B‘;
    

    var k = 1024,
    

    sizes = [‘B‘, ‘KB‘, ‘MB‘, ‘GB‘, ‘TB‘, ‘PB‘, ‘EB‘, ‘ZB‘, ‘YB‘],
    

    i = Math.floor(Math.log(bytes) / Math.log(k));
    

    return (bytes / Math.pow(k, i)).toPrecision(3) + sizes[i];
    

?

JS 小腳本匯聚