要在上传之前和之后预览图像,您需要尝试以下代码-HTML
<script src = "https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script> <form id = "form1" runat = "server"> <input type ='file' id = "demo" /> <img id = "myid" src = "#" alt = "new image" /> </form>
以下是jQuery-
function display(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function(event) { $('#myid').attr('src', event.target.result); } reader.readAsDataURL(input.files[0]); } } $("#demo").change(function() { display(this); });