SoFunction
Updated on 2025-03-06

JS generate random color method code sharing (three types)

Without further ado, please see the code

<!DOCTYPE html>
<html>
<head lang="en">
 <meta charset="UTF-8">
 <title></title>
</head>
<body>
  <button >Call the first type</button>
  <button >Call the second type</button>
  <button >Call the third type</button>
  <script>
   var btn1=('btn1');
   =function(){
    =bg1()
   };
   var btn2=('bnt2');
   =function(){
    =bg2();
   };
   var btn3=('btn3');
   =function(){
    =bg3();
   };
   function bg1(){
    return '#'+(()*256).toString(10);
   }
   function bg2(){
    return '#'+(()*0xffffff).toString(16);
   }
   function bg3(){
    var r=(()*256);
    var g=(()*256);
    var b=(()*256);
    return "rgb("+r+','+g+','+b+")";//The splicing of all methods can be replaced with the new ES6 feature `other string {$ variable name}``   }
  </script>
</body>
</html>

The above is all the content of this article. I hope that the content of this article will help you study or work. I also hope to support me more!