Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/461.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.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
Javascript 如何进行jquery多图像预览_Javascript_Jquery_Html_Css_Ajax - Fatal编程技术网

Javascript 如何进行jquery多图像预览

Javascript 如何进行jquery多图像预览,javascript,jquery,html,css,ajax,Javascript,Jquery,Html,Css,Ajax,这是jquery中的单个图像上传预览功能。我想改变多个功能,如每个框分别上传照片,你可以在下面的html脚本中看到 <!DOCTYPE html> <html> <head> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <link rel="s

这是jquery中的单个图像上传预览功能。我想改变多个功能,如每个框分别上传照片,你可以在下面的html脚本中看到

<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script>

function imagepreview(input){
    if(input.files && input.files[0]){
        var filerd = new FileReader();
        filerd.onload=function(e){
            $('#imgpreview').attr('src', e.target.result);
        };
        filerd.readAsDataURL(input.files[0]);
    }
  }

</script>
<style>
body{
font-family:arial;
}
.wrap{
border:0px solid;
width:40%;
margin:10px auto;
}

table, th, td {
    border: 1px solid black;
    border-collapse: collapse;
    text-align:center;
    padding:10px;
}
#idupload{
    display:none;
}
.input-label{
    background-color:#009688;
    color:#fff;
    padding:5px 15px;
}
</style>
</head>
<body>

<div class="wrap">
<table>
  <tr>
    <th><img id="imgpreview" src="" width="100" height="100"></th>
    <th><img id="imgpreview" src="" width="100" height="100"></th> 
    <th><img id="imgpreview" src="" width="100" height="100"></th>
  </tr>
  <tr>
    <td><label for="idupload" class="input-label"><i class="fa fa-arrow-up"></i>upload</label><input type="file" id="idupload" onchange="imagepreview(this);" /></td>
    <td><label for="idupload" class="input-label"><i class="fa fa-arrow-up"></i>upload</label><input type="file" id="idupload" onchange="imagepreview(this);" /></td>
    <td><label for="idupload" class="input-label"><i class="fa fa-arrow-up"></i>upload</label><input type="file" id="idupload" onchange="imagepreview(this);" /></td>
  </tr>
</table>
</div>

</body>
</html>

函数图像预览(输入){
if(input.files&&input.files[0]){
var filerd=new FileReader();
filerd.onload=函数(e){
$('imgpreview').attr('src',e.target.result);
};
filerd.readAsDataURL(input.files[0]);
}
}
身体{
字体系列:arial;
}
.包裹{
边框:0px实心;
宽度:40%;
利润率:10px自动;
}
表,th,td{
边框:1px纯黑;
边界塌陷:塌陷;
文本对齐:居中;
填充:10px;
}
#上传{
显示:无;
}
.输入标签{
背景色:#009688;
颜色:#fff;
填充:5px15px;
}
上传
上传
上传

问题是您有重复的ID,而函数
imagepreview()
总是在图像上载时更新相同的ID。要解决此问题,请为每个图像预览指定一个唯一的ID,并在文件上载框中放置相同的相应指定,以便唯一的文件上载框将更新唯一的图像预览


这是一个演示。我为预览和上传都提供了一个唯一的ID,然后在
imagepreview()
中解析上传框ID的ID,并将其添加到页面上更新的图像预览ID中

我可以在fb上添加你吗?我想在同一个函数上实现删除图像事件?