首页 > 代码库 > 图片选择器(新)

图片选择器(新)

<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta http-equiv="Expires" content="-1">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Pragma" content="no-cache">
<title>title</title>
<style type="text/css">

</style>
</head>
<body>
<form action="" class="form1">
<input type="file" name="" id="inp1" multiple="multiple">
</form>

<script type="text/javascript">
//添加脚本
var inp1=document.querySelector("#inp1");
var form1=document.querySelector(".form1");
inp1.onchange=function(){
var fileList=inp1.files;
for(var i=0;i<fileList.length;i++){
showImg(fileList[i],form1);
}
};
function showImg(fileItem,form1){
if(fileItem.type.indexOf("image">-1)){
var fileReader=new FileReader();
fileReader.readAsDataURL(fileItem);
fileReader.onload=function(){
var img=new Image();
img.src=http://www.mamicode.com/fileReader.result;
form1.appendChild(img);
};
}
}
</script>
</body>
</html>

 

图片选择器(新)