第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

輸出圖像不出現(xiàn)

輸出圖像不出現(xiàn)

BIG陽 2023-05-11 16:04:44
<form action="">            <h2>Fill out the following details: </h2>                <div class="inp">            <label for="name">Name: </label>            <input type="text" id="name">        </div>        <br>        <div class="inp">            <label for="rollno">Roll No: </label>            <input type="text" id="rollno">        </div>        <br>        <div class="inp">            <label for="image">Image: </label>            <input type="file" id="image" accept="image/jpeg">        </div>        <input type="button" id="submit" value="Submit"></form><div id="output">            <h2>Your Details: </h2>                <div class="out">Name: <span id="outname"></span></div>        <div class="out">Roll No: <span id="outrollno"></span></div>        <div class="out">Image: <img id="outimage" width="200px"></div></div><script type="text/javascript">            function displayImage()        {            var x = document.getElementById("outimage");            var y = document.getElementById("image").src;            x.setAttribute("src",y);        }                document.getElementById("submit").onclick = function()        {            document.getElementById("output").style.display = "block";            document.getElementById("outname").innerHTML = document.getElementById("name").value;            document.getElementById("outrollno").innerHTML = document.getElementById("rollno").value;            displayImage();        }</script>有人能告訴我為什么會這樣嗎?該圖像與 HTML 文件位于同一文件夾中。有沒有更好的方法來實現(xiàn)這一目標(biāo)?我想顯示用戶在表單中選擇的圖像。
查看完整描述

1 回答

?
阿晨1998

TA貢獻2037條經(jīng)驗 獲得超6個贊

您需要確保閱讀了正在上傳的圖像文件的內(nèi)容。使用filereader然后readAsDataURL一旦內(nèi)容被加載通過filereader分配它作為source預(yù)覽圖像占位符。


function readURL() {

  // just to avoid the error since i dont know what readURL is doing nor it is mentioned in the OP.

}


function displayImage() {

  var x = document.getElementById("outimage");

  var file = document.getElementById('image').files[0]

  var fr = new FileReader()

  fr.readAsDataURL(file)

  fr.onload = function(e) {

    x.setAttribute("src", this.result);

  }


}


document.getElementById("submit").onclick = function() {

  document.getElementById("output").style.display = "block";

  document.getElementById("outname").innerHTML = document.getElementById("name").value;

  document.getElementById("outrollno").innerHTML = document.getElementById("rollno").value;

  displayImage();

}

<form action="">


  <h2>Fill out the following details: </h2>


  <div class="inp">

    <label for="name">Name: </label>

    <input type="text" id="name">

  </div>

  <br>

  <div class="inp">

    <label for="rollno">Roll No: </label>

    <input type="text" id="rollno">

  </div>

  <br>

  <div class="inp">

    <label for="image">Image: </label>

    <input type="file" id="image" accept="image/jpeg" onchange="readURL(this)">

  </div>

  <button type="button" id="submit">Submit

</button>

</form>


<div id="output">


  <h2>Your Details: </h2>


  <div class="out">Name: <span id="outname"></span></div>

  <div class="out">Roll No: <span id="outrollno"></span></div>

  <div class="out">Image: <img id="outimage" width="200px"></div>

</div>


查看完整回答
反對 回復(fù) 2023-05-11
  • 1 回答
  • 0 關(guān)注
  • 181 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號