`

按钮随机颜色

阅读更多
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  <title>按钮随机颜色测试</title>
</head>
<body>

<script type="text/javascript">
        function getbuttom(){
        var arr = []//定义一个空的数?
        i =0;//为while循环定义i的初始?
        C = '0123456789ABCDEFGHIJKLMN';//定义颜色代码的字符串
        while(i++ < 6){//循环颜色的位数
        x=Math.random()*16;//随机数给变量x
b=parseInt(x);//整数给变量b
        c=C.substr(b,1);//由第b-16之间的整数)位开始取一个字?
        arr.push(c);//通过6次循环得到的随机位置取得的字符组合在一起把值给到arr这个数组
        }
        var cl = "#"+ arr.join('');//去掉之前数组之间的符号,前面再加一个井号,这样颜色随机的颜色代码就生成了,并且把颜色代码赋值给变量cl
return cl;//把cl的值返回给函数getbuttom()
        }
     function setcolor_zzjs(){
   document.getElementById("input_button").style.backgroundColor = getbuttom();
  }
</script>
<input id="input_button" type="button" value="随机颜色变化" onClick="setcolor_zzjs()" />
</body>
</html>
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics