<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>选择图片并显示</title>
</head>
<body>
<div id="pic_list">
<input type="file" name="files" multiple="multiple" id="doc" οnchange="setImagePreview();">
</div>
<script>
function setImagePreview(avalue) {
var docObj=document.getElementById("doc");
//var imgObjPreview=document.getElementById("preview");
var list = document.getElementById("pic_list");
var button = document.getElementById("file_a");
if(docObj.files) {
if(docObj.files.length==9){
alert("图片数量不能超过9张");
}
//火狐下,直接设img属性
for(var i=0;i<docObj.files.length;i++){
var imgObjPreview = document.createElement("img");
imgObjPreview.className = "dtbj_pic";
imgObjPreview.name="images";
imgObjPreview.style.width = '60px';
imgObjPreview.style.height = '60px';
imgObjPreview.style.margin = "10px";
//imgObjPreview.src = docObj.files[0].getAsDataURL();
//火狐7以上版本不能用上面的getAsDataURL()方式获取,需要一下方式
imgObjPreview.src = window.URL.createObjectURL(docObj.files[i]);
list.insertBefore(imgObjPreview,button);
}
}
return true;
}
</script>
</body>
</html>