我编写了此代码及其工作原理,但是当我选择图像时,所有输入均查看同一图像,而不仅是我将图像添加到..的图像。>>
<html lang="en"> <head> <title>Change image on select new image from file input</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script> </head> <body> <ul> <li> <input type="file" name="file" class="profile-img"> <img src="" class="profile-img-tag" width="200px" /> </li> <li> <input type="file" name="file" class="profile-img"> <img src="" class="profile-img-tag" width="200px" /> </li> <li> <input type="file" name="file" class="profile-img"> <img src="" class="profile-img-tag" width="200px" /> </li> </ul> <script type="text/javascript"> function readURL(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function (e) { $('.profile-img-tag').attr('src', e.target.result); } reader.readAsDataURL(input.files[0]); } } $(".profile-img").change(function(){ readURL(this); }); </script> </body> </html>
仅不能分开进行每个输入。
[我编写了此代码及其工作原理,但是当我选择图像时,所有输入均查看同一图像,不仅是我将图像添加到..