3 回答

TA貢獻(xiàn)1804條經(jīng)驗 獲得超2個贊
每次附加圖像源之前檢查圖像值是否為空。如果為空,則不執(zhí)行任何其他操作,附加圖像 atr 或 source 。
當(dāng)您在圖像屬性上添加任何內(nèi)容時,它顯示的邊框意味著沒有找到圖像或未找到 img url。
const loadFile = function(event) {
const output = document.getElementById('output');
output.src = URL.createObjectURL(event.target.files[0]);
output.onload = function() {
URL.revokeObjectURL(output.src) // free memory
}
};
<input type="file" accept="image/*" onchange="loadFile(event)">
<img id="output"/>

TA貢獻(xiàn)1934條經(jīng)驗 獲得超2個贊
首先添加隱藏圖像的樣式
#uploadPreview{
display:none;
}
function PreviewImage() {
var oFReader = new FileReader();
oFReader.readAsDataURL(document.getElementById("uploadImage").files[0]);
if(oFReader == "" || oFReader== null){
alert("image is empty")
}else{
oFReader.onload = function (oFREvent) {
document.getElementById("uploadPreview").src = oFREvent.target.result;
document.getElementById("uploadPreview").style = "display:block";
}
};
};

TA貢獻(xiàn)1951條經(jīng)驗 獲得超3個贊
也許可以用類似的東西來設(shè)計圖像線條:
border-width:0px; border:none;
這應(yīng)該消除任何類型的邊界。
或者添加一個
display:none
完全隱藏圖像。
- 3 回答
- 0 關(guān)注
- 151 瀏覽
添加回答
舉報