<html>
<head>
<title> New Document </title>
<meta name=
"Generator"
content=
"EditPlus"
>
<meta name=
"Author"
content=
""
>
<meta name=
"Keywords"
content=
""
>
<meta name=
"Description"
content=
""
>
</head>
<body>
<script type=
"text/javascript"
>
function
$$(id){
return
document.getElementById(id);
}
function
filePrevImg(files){
if
(typeof FileReader ==
"undefined"
){
alert(
"您的浏览器不支持FileReader对象!"
);
}
var
strHtml =
""
;
for
(
var
intI=0;intI<files.length;intI++){
var
tmpFile = files[intI];
var
reader =
new
FileReader();
reader.readAsDataURL(tmpFile);
reader.onload=
function
(e){
alert(e.target.result);
strHtml +=
"<img src='"
+e.target.result+
"' alt=''/>"
;
$$(
"prevUpload"
).innerHTML =
"<li>"
+strHtml+
"</li>"
;
};
}
}
</script>
</head>
<body>
<fieldset>
<legend>使用readAsDataUrl()方法预览图片</legend>
<input type=
"file"
name=
"fileUpload"
id=
"fileUpload"
onchange=
"filePrevImg(this.files);"
multiple=
"true"
/>
<ul id=
"prevUpload"
></ul>
</fieldset>
</body>
</html>