如果没有历史记录,我如何隐藏图像或按钮onclick=;历史.go(-1);

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

本文关键字:历史 按钮 go 图像 onclick 隐藏 记录 何隐藏 如果没有      更新时间:2023-09-26

我对Go BackGo 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
}