标签:随机 json htm location onclick type ring har bsp
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <script> window.onload = function(){ var oInput = document.getElementsByTagName(‘input‘)[0]; var oDiv = document.getElementsByTagName(‘div‘)[0]; var json = {}; oInput.onclick = function(){ var num = Math.random(); var arr = randomNum(35,7); json[num] = arr; window.location.hash = num; oDiv.innerHTML = arr; }; window.onhashchange = function(){ oDiv.innerHTML = json[window.location.hash.substring(1)]; }; }; function randomNum(iNumber,iNow){ var arrNumber = []; var newNumber = []; for(var i=0;i<=iNumber;i++){ arrNumber.push(i); } for(var i=0;i<iNow;i++){ newNumber.push(arrNumber.splice(Math.floor(Math.random()*arrNumber.length),1)); } return newNumber; } </script> </head> <body> <input type="button" value="产生随机数"/> <div></div> </body> </html>
标签:随机 json htm location onclick type ring har bsp
原文地址:https://www.cnblogs.com/moon-yyl/p/9063718.html