Xavier在another thread上发布了这个解决方案,并且我试图将它改进以适应多个文件输入。我希望它有帮助。
$("body").on('change', 'input:file', function(e){
for (var i = 0; i < e.originalEvent.srcElement.files.length; i++) {
var file = e.originalEvent.srcElement.files[i];
var img = document.createElement("img");
var reader = new FileReader();
reader.onloadend = function() {
img.src = reader.result;
}
img.width = "50";
reader.readAsDataURL(file);
if($(this).next().hasClass('image_place')){
$(this).next('.image_place').html('').append(img);
}else {
$(this).after('<div class="image_place"></div>');
$(this).next('.image_place').append(img);
}
}
});
它扫描文档正文中的所有文件输入并使用FileReader API读取图像。如果它找到任何图像,它将创建一个名为“image_place”的div,在其中放置图像。如果里面已经有图像,脚本会替换图像。
重复:http:// stackoverflow。COM /问题/ 771581/IS-有-任何路至显示器的图像,在客户端的浏览器,而无需上载,其对服务 – galambalazs 2010-07-11 13:08:50