zoukankan      html  css  js  c++  java
  • h5中history实例

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
    </head>
    <body>
        <button id="btn">按钮</button>
        <div id="div1">
    
        </div>
    </body>
    <script>
        let oBtn = document.getElementById('btn');
        let oDiv = document.getElementById('div1');
        let obj = {};
        let iNow = 1;
    
        oBtn.onclick = function(){
            var number = randomNum(35,7);
            oDiv.innerHTML = number;
            window.history.pushState(null,'',iNow++);  //注意必须在服务器环境下,否则会报错
        }
        window.onpopstate = function(ev){
            var number = ev.state || '';
            oDiv.innerHTML = number;
        }
    
        function randomNum(alls,now){
            var arr = [];
            var newArr = [];
            for(var i=1;i<=alls;i++){
                arr.push(i);
            }   
            for(var i=0;i<now;i++){
                newArr.push(arr.splice(Math.floor(Math.random()*arr.length),1));
            }
            return newArr;
        }
        
    </script>
    </html>
  • 相关阅读:
    http缓存
    深入理解vertical-align
    WebSocket
    mongodb 语法小结
    鸡肋工具-Oracle建表工具
    Ajax 实现导出文件-支持批量
    Springboot 热部署
    RabbitMq(7)消息延时推送
    linux常用符号命令
    linux常用命令之文档
  • 原文地址:https://www.cnblogs.com/chenzhiyu/p/9002758.html
Copyright © 2011-2022 走看看