0

我想使用带有 SuccessFactors 的 JavaScript 来检查上传照片的大小是否大于 2 MB。

我编写了以下 JavaScript 代码,但它似乎不起作用:

if (context.files.length > 0) {
    for (const i = 0; i <= context.files.length - 1; i++) {
        const fsize = context.files.item(i).size;
        const file = Math.round((fsize / 1024));

        if (file >= 4096) {
            alert("File too Big, please select a file less than 4mb");
        }
    }
}
4

1 回答 1

0

您可以使用 for of 来遍历文件列表

if (context.files.length > 0) {
          for (let file of context.files) {
            const size = Math.round(file.size / 1024);
            if (size >= 4096) {
              alert("File too Big, please select a file less than 4mb");
            }
          }
        }
于 2021-03-01T18:04:06.570 回答