上传图片预览
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<style type="text/css">
#preview, .img, img
{
width:200px;
height:200px;
}
#preview
{
border:1px solid #dedede;
}
/*a upload */
.a-upload {
width:200px;
height: 200px;
text-align:center;
text-decoration: none;
line-height: 20px;
position: relative;
bottom:202px;
opacity:0;
cursor: pointer;
color: #888;
background: #fafafa;
border: 1px solid #ddd;
border-radius: 4px;
overflow: hidden;
display: inline-block;
*display: inline;
*zoom: 1
}
.a-upload input {
position: absolute;
font-size: 16px;
right: 0;
top: 0;
opacity: 0;
filter: alpha(opacity=0);
cursor: pointer
text-decoration:none;
width:200px;
height: 200px;
}
.a-upload:hover {
}
</style>
</head>
<body>
<div id="preview"></div>
<a href="javascript:;" class="a-upload">
<input type="file" onchange="preview(this)" />
</a>
<script type="text/javascript">
function preview(file)
{
var prevDiv = document.getElementById('preview');
if (file.files && file.files[0])
{
var reader = new FileReader();
reader.onload = function(evt){
prevDiv.innerHTML = '<img src="' + evt.target.result + '" />';
}
reader.readAsDataURL(file.files[0]);
}
else
{
prevDiv.innerHTML = '<div class="img" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src=\'' + file.value + '\'"></div>';
}
}
</script>
</body>
</html>
学习是一个不断抄袭和重复的过程.

浙公网安备 33010602011771号