拖放本地资源
Index.html
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>拖放</title>
<script src="app1.js"></script>
<style>
#imgcontainer{
width: 400px;
height: 400px;
background-color: antiquewhite;
}
</style>
</head>
<body>
<div id="imgcontainer"></div>
<div id="msg"></div>
</body>
</html>
app1.js
/**
* Created by lenovo on 2016/7/4.
*/
var msgdiv,imgcontainer;
window.onload=function(){
msgdiv=document.getElementById("msg");
imgcontainer=document.getElementById("imgcontainer");
imgcontainer.ondragover=function(e){
e.preventDefault();
}
imgcontainer.ondrop=function(e){
e.preventDefault();
var f= e.dataTransfer.files[0];
var fileReader=new FileReader();
fileReader.onload=function(e){
imgcontainer.innerHTML="<img src=\""+fileReader.result+"\">";
}
fileReader.readAsDataURL(f);
}
}