日期:2014-05-16 浏览次数:20408 次
function display(x){
document.getElementById('p').style.display = x;
}
function pric(){
var p = document.getElementById('file');
p.click();
document.getElementById('img').src = p.value;
}
<a href="javascript:;" onclick="display('block')">修改头像</a>
<center>
<div class="lk" id="p" style="display:none">
<div id="d">
<div class="c">
<input style="display:none;" id="file" type="file" />
<img id="img" width="100" height="100" />
</div>
<div class="b">
<a href="#" onclick="display('none')">上传</a>
<a href="#" onclick="pric()">预览</a>
</div>
</div>
</div>
</center>
<img id="uploadPreview" style="width: 100px; height: 100px;" />
<input id="uploadImage" type="file" name="myPhoto" onchange="PreviewImage();" />
<script type="text/javascript">
function PreviewImage() {
oFReader = new FileReader();
oFReader.readAsDataURL(document.getElementById("uploadImage").files[0]);
oFReader.onload = function (oFREvent) {
document.getElementById("uploadPreview").src = oFREvent.target.result;
};
};
</script>