簡體   English   中英

如果沒有歷史記錄,我該如何隱藏圖像或按鈕onclick =“ history.go(-1);

[英]How can i hide image or button if there is no history onclick="history.go(-1);

我使用兩個導航按鈕進行Go BackGo Back Go Previous但是如果沒有“上一個”或“上一個”歷史記錄,該如何隱藏

<img style="width: 150px;" onclick="history.go(-1);" src="go-back-button2.png"/>

<img style="width: 150px;" onclick="history.go(+1);" src="go-back-button1.png"/>

檢測是否只有一個項目,然后將元素隱藏或變灰:

 <!DOCTYPE html>
<html>
<body>
    <img id="back" style="width: 150px;" onclick="history.go(-1);" src="go-back-button2.png"/>

<img style="width: 150px;" onclick="history.go(+1);" src="go-back-button1.png"/>
<script>
    if(history.length===1){
    document.getElementById('back').style.display='none';};
</script>
</body>
</html>

只需使用history.lenght像://在按鈕上添加ID

if (history.length > 1){
 //hide button based on id
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM