zoukankan      html  css  js  c++  java
  • js随机生成验证码和颜色

    //页面加载时执行的代码

    <body onload="sj()">

    <div style="120px;height:20px;border:1px solid black;float:left;">
    <span id="sz1">1</span><span id="sz2">2</span><span id="sz3">3</span><span id="sz4">4</span>
    </div>
    <button onclick="sj()">刷新按钮</button>

    </body>

    //将分装函数代入

    <script type="text/javascript">
    function sj(){
    document.getElementById("sz1").innerHTML=sz();
    document.getElementById("sz2").innerHTML=sz();
    document.getElementById("sz3").innerHTML=sz();
    document.getElementById("sz4").innerHTML=sz();
    document.getElementById("sz1").style.color=$color();
    document.getElementById("sz2").style.color=$color();
    document.getElementById("sz3").style.color=$color();
    document.getElementById("sz4").style.color=$color();
    }

    </script>

    //分装的随机数

    function sz(){
    var met= new Array('a','b','c','d','e','f','g','h','i','g','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',"0","1","2","3","4","5","6","7","8","9");
    var z1=met[Math.round(Math.random()*(met.length-1))];
    return z1;
    }

    //分装的随机颜色

    function $color(){
    var r= Math.round(Math.random()*255);
    var g= Math.round(Math.random()*255);
    var b= Math.round(Math.random()*255);
    var rgb="rgb("+r+","+g+","+b+")";
    return rgb;
    }

  • 相关阅读:
    eclipse如何设置多个字符的智能提示
    19.面向对象的三大特征 之封装
    18代码块
    成员变量和局部变量的区别
    类与对象
    Python压缩脚本编辑
    字符串内容
    参考
    序列
    元组
  • 原文地址:https://www.cnblogs.com/king-govern/p/8202617.html
Copyright © 2011-2022 走看看