JS:
var h5 = {
cache : {},
init : function(){
cache.$file = document.getElementById('file');
cache.$file.addEventListener('drop', this.drop_handle, false);
},
drop_handle : function(e){
e.stopPropagation();
e.preventDefault();
var files = e.target.files || e.dataTransfer.files;
console.info(files);
return false;
}
}
h5.init();
HTML:
<input type="file" name="" id="file" style="font-size:5em">
在 ff 或 chrome 中,把文件拖放进去到 file 按钮,console.log 出来的是空文件信息,这段代码有哪里有错吗?怎么看也没有错吧……
1
Arrowing 2014-11-24 17:35:24 +08:00
<input type="file" name="" id="file" style="font-size:5em" draggable="true">
this.cache.$file = document.getElementById('file'); this.cache.$file.addEventListener('drop', this.drop_handle, false); |
2
typcn 2014-11-24 17:37:58 +08:00 1
|
3
Arrowing 2014-11-24 17:43:33 +08:00
var files = (e.target.files.length && e.target.files) || e.dataTransfer.files;
|
4
kmvan OP |