码迷,mamicode.com
首页 > 其他好文 > 详细

h5中hash的用法实例

时间:2018-05-07 14:45:11      阅读:886      评论:0      收藏:0      [点我收藏+]

标签:tle   dev   func   floor   bst   spl   cti   1.0   col   

<!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 = {};


    oBtn.onclick = function(){
        var number = randomNum(35,7);
        oDiv.innerHTML = number;
        var MRN = Math.random();
        obj[MRN] = number;
        window.location.hash = MRN;

    }
    window.onhashchange = function(){
        var number = obj[window.location.hash.substring(1)] || ‘‘;
        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>

 

h5中hash的用法实例

标签:tle   dev   func   floor   bst   spl   cti   1.0   col   

原文地址:https://www.cnblogs.com/chenzhiyu/p/9002316.html

(1)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!