本文转载自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
})
继续加油,一步一步��