<body onload="color()"></body>

<script>

 function color(){

方法一:

     document.getElementByTagName("body").style.background = '#'+Math.floor(Math.random()*256).toString(10);

方法二:

     document.getElementByTagName("body").style.background = '#'+Math.floor(Math.random()*0xffffff).toString(16);

方法三:

     var r=Math.floor(Math.random()*256);
     var g=Math.floor(Math.random()*256);
     var b=Math.floor(Math.random()*256);
     document.getElementsByTagName("body")[0].style.background = "rgb("+r+','+g+','+b+")";    //所有方法的拼接都可以用ES6新特性`其他字符串{$变量名}`替换

}

</script>

相关文章:

  • 2022-02-20
  • 2021-08-21
  • 2022-12-23
  • 2022-12-23
  • 2021-08-09
  • 2021-09-26
  • 2022-02-14
  • 2022-01-17
猜你喜欢
  • 2022-01-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-07
相关资源
相似解决方案