Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 在另一个div顶部显示所选图像_Html_Css - Fatal编程技术网

Html 在另一个div顶部显示所选图像

Html 在另一个div顶部显示所选图像,html,css,Html,Css,当我选择一个图像时,我可以预览它。但它显示在upload data div上方 一旦选择图像预览div将显示在上传数据div顶部,我将尝试实现什么 问题:选择图像后,如何使预览图像显示在上载数据div的顶部 代码笔 HTML jQuery function readURL(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload =

当我选择一个图像时,我可以预览它。但它显示在upload data div上方

一旦选择图像预览div将显示在上传数据div顶部,我将尝试实现什么

问题:选择图像后,如何使预览图像显示在上载数据div的顶部

代码笔

HTML

jQuery

function readURL(input) {

  if (input.files && input.files[0]) {
    var reader = new FileReader();

    reader.onload = function(e) {
      $('.upload-image img').attr('src', e.target.result);
    }
    reader.readAsDataURL(input.files[0]);
  }
}

$(".file-input").change(function(){
    $('.upload-image').append('<img>');
    readURL(this);
});
函数readURL(输入){
if(input.files&&input.files[0]){
var reader=new FileReader();
reader.onload=函数(e){
$('.upload image img').attr('src',e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$(“.file input”).change(函数(){
$('.upload image').append('');
readURL(this);
});
代码笔:

只要用户选择一个文件,我就简单地隐藏了
upload data
div。如果用户想要选择另一个文件,可以单击“添加取消”按钮并取消隐藏div

$(".file-input").change(function(){
    $('.upload-image').append('<img>');
    $('.upload-data').hide(); //Hide the div.
    readURL(this);
});
function readURL(input) {

  if (input.files && input.files[0]) {
    var reader = new FileReader();

    reader.onload = function(e) {
      $('.upload-image img').attr('src', e.target.result);
    }
    reader.readAsDataURL(input.files[0]);
  }
}

$(".file-input").change(function(){
    $('.upload-image').append('<img>');
    readURL(this);
});
$(".file-input").change(function(){
    $('.upload-image').append('<img>');
    $('.upload-data').hide(); //Hide the div.
    readURL(this);
});
$('.upload-data').show();