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();

    代码改变了我们,也改变了世界
  • 相关阅读:
    支持向量机SVM知识点概括
    决策树知识点概括
    HDU 3081 Marriage Match II
    HDU 3572 Task Schedule
    HDU 4888 Redraw Beautiful Drawings
    Poj 2728 Desert King
    HDU 3926 Hand in Hand
    HDU 1598 find the most comfortable road
    HDU 4393 Throw nails
    POJ 1486 Sorting Slides
  • 原文地址:https://www.cnblogs.com/wencaiguagua/p/13586103.html
Copyright © 2011-2022 走看看