javascript - Why is the image size I get here NaN?
巴扎黑
巴扎黑 2017-05-19 10:42:49
0
3
512
    <form enctype="multipart/form-data" name="form1">
      <input type="file" name="file">
      <input type="button" value="取得图片的大小" onClick="getSize()">
    </form>
    <img name="pic" alt="在这儿显示图片">
function getSize(){
        size = 0;
        imgURL = form1.file.value;
        imgURLsplice = imgURL.split("\").pop();
        imgURLsplicelocal ="../assets/img/" + imgURLsplice;
        img = new Image();
        img.src = imgURLsplicelocal;
        pic.src = imgURLsplicelocal;
        if (size <= 0){
            size = img.fileSize / 1024;
        }
        alert("图片大小为:" + size + "KB");
    }

巴扎黑
巴扎黑

reply all(3)
世界只因有你

img.fileSize is a number not a character

伊谢尔伦

You will know after taking a look at the img.fileSize log.

Ty80
img是个dom类型<img>的东西啊。怎么可能有fileSize这种东西
$("#file")[0].files[0].size才可以有

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!