<!Doctype html>
<html>
<head>
<title>上传图片显示预览图</title>
<style>
#result img{
height:100px;
display:inline-block;
margin-right:10px;
margin-bottom:10px;
}
</style>
</head>
<body>
<div class="add_imgs">
<p>
<label>请选择一个图像文件:</label>
<input type="file" id="file_input" style="display:none;" />
</p>
<div id="result">
<a href="javascript:void(0);" class="add_img_btn">添加图片</a>
</div>
</div>
<div class="add_imgs">
<p>
<label>请选择一个图像文件:</label>
<input type="file" id="file_input" style="display:none;" />
</p>
<div id="result">
<a href="javascript:void(0);" class="add_img_btn">添加图片</a>
</div>
</div>
<script src="jquery-2.2.1.min.js"></script>
<script>
$(".add_img_btn").unbind("click").on("click",function(){
$(this).parents(".add_imgs").find("input[type=file]").click();
var result = $(this).parent();
var input = $(this).parents(".add_imgs").find("input[type=file]");
dads(result,input);
})
function dads(result,input){
if(typeof FileReader==='undefined'){
result.innerHTML = "抱歉,你的浏览器不支持 FileReader";
input.setAttribute('disabled','disabled');
}else{
$(input).unbind("change").on("change",function(){
var file = this.files[0];
if(!/image/w+/.test(file.type)){
alert("文件必须为图片!");
return false;
}
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function(e){
$(result).append('<img src="'+this.result+'" alt="" />');
}
})
}
}
</script>
</body>
</html>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有