e.target.files[0]层层剖析

9 篇文章 0 订阅
4 篇文章 0 订阅

     本文转载自http://www.cnblogs.com/lwwen/p/6210126.html

因为我现在拿到的一个功能是上传时过滤掉很大尺寸的图片,所以需要来拿到上传时选择图片的size,所以有了这篇博文


不多说 上代码

$('input').change(function(e){

 1️⃣、console.log(e)==>得到的是什么呢

  得到的是:下面这些

    altKey:undefined
    bubbles:true
    cancelable:false
    ctrlKey:undefined
    currentTarget:input
    data:null
    delegateTarget:input
    detail:undefined
    eventPhase:2
    handleObj:Object
    isDefaultPrevented:h()
    jQuery22007808826687871413:true
    metaKey:undefined
    originalEvent:Event
    relatedTarget:undefined
    shiftKey:undefined
    target:input
    timeStamp:3956.0400000000004
    type:"change"
    view:undefined
    which:undefined
    __proto__:Object      

2️⃣、console.log(e.target)又会得到什么呢?

  得到的是input对象<input type="file" multiple="multiple" style="top: 91px; left: 44px; position: absolute; opacity: 0; z-index: 1000;">

3️⃣、console.log(e.target.files)呢,得到的又是什么呢?

  得到的是一串filelist

    FileList
        length:0
        __proto__:FileList

4️⃣、console.log(e.target.files[0])又能得到什么呢

  得到的是第一张input选择的图片的一些参数,得到的这些参数可以根据自己的需要提取,比如我现在需要的是size参数,e.target.files[0].size就可以拿到了,得到的单位是b哈

    File
        lastModified:1478486422000
        lastModifiedDate:Mon Nov 07 2016 10:40:22 GMT+0800 (CST)
        name:"222.jpg"
        size:124996
        type:"image/jpeg"
        webkitRelativePath:""
        __proto__:File

})

 继续加油,一步一步��
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值