zoukankan      html  css  js  c++  java
  • 点击div随机变色

     1 <!DOCTYPE html>
     2 <html lang="en">
     3 <head>
     4   <meta charset="UTF-8">
     5   <meta name="viewport" content="width=device-width, initial-scale=1.0">
     6   <title>Document</title>
     7   <style>
     8     #box {
     9        200px;
    10       height: 200px;
    11       background: red;
    12     }
    13   </style>
    14 </head>
    15 <body>
    16   <div id="box"></div>
    17   <script>
    18     var box = document.getElementById('box')
    19     box.onclick = function () {
    20       // 生成一个随机颜色
    21       var str = '0123456789abcdef'
    22       var color = '#'
    23       for (var i = 0; i < 6; i++) {
    24         var index = Math.floor(Math.random() * str.length)
    25         color += str[index]
    26       }
    27       console.log(color)
    29       box.style.background = color
    30     }
    31   </script>
    32 </body>
    33 </html>
  • 相关阅读:
    微信扫码
    vue h5公众号支付
    vue h5支付宝支付
    vue PDF预览
    vue 中AES加密
    vue 动态路由配置
    移动端调试工具
    Ajax工作原理
    yahoo军规
    Flex 布局教程
  • 原文地址:https://www.cnblogs.com/strongerPian/p/12716477.html
Copyright © 2011-2022 走看看