[英]Can't see a DOM node's style visibility through Javascript
我需要在Javascript中添加一些邏輯,以使捕獲事件的節點的父節點消失。 具體來說,父節點是PDF鏈接,如果子節點無法加載,則其及其子節點(bmp圖像)都必須不可見。 這是我概述為事件偵聽器功能的內容:
window.addEventListener('error', function(event) {
console.log(event);
if (event.target.id == "sheetBmp"){
console.log("sheet bmp failed to load");
//make the pdf disappear also
e.target.parentNode.style.visibility=false;
console.log("pdf nodeshould disappear");
}
}, true);
這是樣式:
<a id=sheetPdf target='_blank'>
<img id="sheetBmp" onLoad="this.style.visibility='visible'" onError="this.style.visibility='hidden'">
</img>
</a>
請注意,我是通過調試器在e.target.parentNode.style.visibility=false;
之后運行的e.target.parentNode.style.visibility=false;
行運行時,屬性保持不變(雙引號),並且節點的可見性在網頁上仍然可見。 非常感謝任何幫助
您正在為屬性設置一個無效值( false
),因此瀏覽器將其丟棄。
可見性屬性的可接受值包括"visible"
和"hidden"
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.