24 September 2016

Xem hình ảnh trước khi được tải lên Preview an image before it is uploaded

Html
Java 2016
//Input image
<input type="file" accept="image/*" onchange="loadFile(event)"> //Input image

//Output image
<img id="output"/>
Or Javascript - 1
Java 2016
<script>
  var loadFile = function(event) {
    var output = document.getElementById('output');
    output.src = URL.createObjectURL(event.target.files[0]);
  };
</script>
Or Javascript - 2
Java 2016
<script>
  var loadFile = function(event) {
    var reader = new FileReader();
    reader.onload = function(){
      var output = document.getElementById('output');
      output.src = reader.result;
    };
    reader.readAsDataURL(event.target.files[0]);
  };
</script>
 > Run demo

0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang