h5中hash的用法实例
Posted 阿弥陀佛么么哒!
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了h5中hash的用法实例相关的知识,希望对你有一定的参考价值。
<!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的用法实例的主要内容,如果未能解决你的问题,请参考以下文章