zoukankan      html  css  js  c++  java
  • js随机验证码

    function randomColor() {
    var colorValue = "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f";
    var colorArray = colorValue.split(",");
    var color = "#";
    for (var i = 0; i < 6; i++) {
    color += colorArray[Math.floor(Math.random() * 16)];
    }
    return color;
    }

    function getRandomNum(n) {
    return parseInt(Math.random() * n);
    }

    function getVerification() {
    var ctx = document.getElementById("canvas").getContext("2d");
    ctx.clearRect(0, 0, 400, 400);
    // 设置字体
    ctx.font = "128px bold 黑体";
    // 设置垂直对齐方式
    ctx.textBaseline = "top";
    // 设置颜色
    ctx.fillStyle = randomColor();
    // 绘制文字(参数:要写的字,x坐标,y坐标)
    ctx.fillText(getRandomNum(10), 0, getRandomNum(50));
    ctx.fillStyle = randomColor();
    ctx.fillText(getRandomNum(10), 50, getRandomNum(50));
    ctx.fillStyle = randomColor();
    ctx.fillText(getRandomNum(10), 100, getRandomNum(50));
    ctx.fillStyle = randomColor();
    ctx.fillText(getRandomNum(10), 150, getRandomNum(50));
    }
    getVerification();

    代码改变了我们,也改变了世界
  • 相关阅读:
    单链表
    顺序表
    关于传输协议的简单了解
    URL/URI/URN
    点击图片弹出轮播图 -- 插件
    nodeJs中系统模块的常用方法和自定义模块暴露
    Buffer
    Sublime Text 3 安装Package Control
    npm的简单使用
    scrollTop()和document.body.scrollTop的区别
  • 原文地址:https://www.cnblogs.com/wencaiguagua/p/13586103.html
Copyright © 2011-2022 走看看