image-upload.js 493 B

123456789101112131415161718
  1. (function () {
  2. document
  3. .getElementById("imageUpload")
  4. .addEventListener("change", readURL, true);
  5. function readURL() {
  6. const file = document.getElementById("imageUpload").files[0];
  7. const reader = new FileReader();
  8. reader.onloadend = function () {
  9. document.getElementById("image").style.backgroundImage =
  10. "url(" + reader.result + ")";
  11. };
  12. if (file) {
  13. reader.readAsDataURL(file);
  14. } else {
  15. }
  16. }
  17. })();