e.target.files[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

})

 繼續加油,一步一步�
發佈了41 篇原創文章 · 獲贊 57 · 訪問量 71萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章