<html>
<head>
<meta charset="UTF-8">
<title>Droid</title>
<style type="text/css">
ul li {
float: left
list-style: none
padding-right: 10px
}
</style>
<script type="text/javascript" src="jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$ (function ()
{
var oUll = $ ("#ul"), FR, source = $ (':file')
if (!!(FR = $ (window).prop ('FileReader')))
{
var fr = new FR ()
$ ("#btn").click (function ()
{
var file = source.prop ('files')[0]
if (!file)
{
return false
}
var aLi = $ ("<li></li>")
var aImg = $ ("<img />")
oUll.append (aLi)
aLi.append (aImg)
var imgs = $ ("img")
fr.onloadend = function (e)
{
imgs.eq (imgs.length - 1).attr ('src', e.target.result)
source.val ('')
}
fr.readAsDataURL (file)
})
}
})
</script>
</head>
<body>
<input type="file" name="file" />
<input id="btn" type="button" value="添加" />
<ul id="ul"></ul>
</body>
</html>
这个简单代码:var read = new FileReader()
read.readAsDataURL(files)
read.onload = function (e) {
var src = e.target.result
$("#img")..attr("src", src)
}