Advertisement
jiue123

Lấy image trước khi upload

Apr 1st, 2015
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.67 KB | None | 0 0
  1. Phần Html
  2.  
  3. <a href="http://lesson8.blogspot.com/">http://lesson8.blogspot.com/</a>
  4.  
  5. <form id="form1" runat="server">
  6.     <input type='file' id="inputFile" />
  7.     <img id="image_upload_preview" src="http://placehold.it/100x100" alt="your image" />
  8. </form>
  9.  
  10. Phần JS
  11.  
  12.     function readURL(input) {
  13.         if (input.files && input.files[0]) {
  14.             var reader = new FileReader();
  15.  
  16.             reader.onload = function (e) {
  17.                 $('#image_upload_preview').attr('src', e.target.result);
  18.             }
  19.  
  20.             reader.readAsDataURL(input.files[0]);
  21.         }
  22.     }
  23.  
  24.     $("#inputFile").change(function () {
  25.         readURL(this);
  26.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement