h5历史管理

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>h5历史管理</title>
<script>
window.onload = function(){
  var odiv = document.querySelector('#box');
  var oipt = document.querySelector('input');

  oipt.onclick = function(){

    var arr = randomNum(35,7);

    history.pushState(arr,'');

    odiv.innerHTML = arr;

  };
  function randomNum(iAll, iNow){
    var arr = [];
    var nArr = [];
    for(var i = 1;i <= iAll; i++){
      arr.push(i);
    }

    for(var i = 0; i< iNow; i++){
      nArr.push(arr.splice(Math.floor(Math.random()*arr.length),1));
    }
    return nArr;
  }
  window.onpopstate = function(ev){
    odiv.innerHTML = ev.state;
  }
}

</script>
</head>
<body>

<input type="button" value="随机选择" id="btn">

<div id="box" data-name='vsmart' class="box box2 box3">box1</div>


</body>
</html>

posted on 2017-04-10 14:29  vsmart  阅读(202)  评论(0编辑  收藏  举报