亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

如何使用 JavaScript 在另一個頁面中獲取圖像 src?

如何使用 JavaScript 在另一個頁面中獲取圖像 src?

弒天下 2023-06-15 10:25:20
我有兩個 HTML 頁面;main.html和result.html。主要.html:    <img id="preview" src="" alt="">    <button id="done" type="button">done</button>結果.html:    <img id="search" src="" alt="">在main頁面中,我上傳了一張圖片,預覽顯示在previewof中main。然后我使用 cropper js 模塊裁剪了這張圖片。crop.js:const done = document.getElementById('done');const imgcropped = document.getElementById('img-cropped');done.addEventListener('click', (e) => {    imgcropped.src = cropper.getCroppedCanvas().toDataURL();})我想去imgcropped.src里面search.src。result我怎樣才能得到main圖像result?
查看完整描述

1 回答

?
UYOU

TA貢獻1878條經驗 獲得超4個贊

您可以使用localStorage.


在 main.html 中:


const done = document.getElementById('done');

const imgcropped = document.getElementById('img-cropped');


done.addEventListener('click', (e) => {

    var newSrc = cropper.getCroppedCanvas().toDataURL();

    imgcropped.src = newSrc;

    window.localStorage.setItem("imgcropped", newSrc);

});

在 result.html 中:


var searchImg = document.getElementById("search")

if(window.localStorage.getItem("imgcropped") !== null){

    searchImg.src = window.localStorage.getItem("imgcropped");

}


查看完整回答
反對 回復 2023-06-15
  • 1 回答
  • 0 關注
  • 160 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號