54 history对象

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <script>
            /*
                history是window对象的属性,它保存这个用户上网的记录


                属性
                history.length  返回当前history对象中记录数
                (历史记录的条数)


                方法
                history.back()          返回上一条历史记录,类似后退
                history.forward()       前进到下一条历史记录,类似前进
                history.go()            
                    参数:0 重载当前页面  
                        正数 前进对应数量的记录
                        负数 后退对应数量的记录 
            */
            window.onload = function(){
                var oBen = document.getElementById("btn")
                oBen.onclick = function(){
                    alert(history.length)
                }


                
                var oKen = document.getElementById("back")
                oKen.onclick = function(){
                    window.history.back()
                }

                var oFen = document.getElementById("for")
                oFen.onclick = function(){
                    window.history.forward()
                }

                var Ogo = document.getElementById("go")
                Ogo.onclick = function(){
                    history.go(1)
                }

            }
        </script>
    </head>
    <body>
        <input type="button" value="记录" id="btn">
        <input type="button" value="后退" id="back">
        <input type="button" value="前进" id="for">
        <input type="button" value="go" id="go">
    </body>
</html>
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容