LoginSignup
0
0

More than 3 years have passed since last update.

プレビュー機能 

Posted at

if (document.URL.match(/new/) || document.URL.match(/edit/)) {
document.addEventListener('DOMContentLoaded', function () {
const ImageList = document.getElementById("image-list")
document.getElementById('message_image').addEventListener('change', function (e) {

  // 投稿した時、既に画像が表示されている場合は、その画像を削除する
  const imageContent = document.querySelector('img');
  if (imageContent) {
    imageContent.remove();
  }


  //console.log(e); 画像のパスを調べる e.target.files[0]
  const file = e.target.files[0];                      //一番最新の画像
  const blob = window.URL.createObjectURL(file);       //最新の画像のURLを作成 

  const imageElement = document.createElement('div');  // 画像を表示するためのdiv要素を生成

  const blobImage = document.createElement('img');     // 表示する画像要素を生成
  blobImage.setAttribute('src', blob);                 //最新の画像のURLを指定

  // 生成したHTMLの要素をブラウザに表示させる
  imageElement.appendChild(blobImage); //最新の画像をdivに
  ImageList.appendChild(imageElement); //divをWindows画面に
});

});

}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0