以下是一个示例的 createCaptcha() 函数,可以用来生成简单的字母数字验证码:

function createCaptcha() {
  const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  let captcha = '';
  for (let i = 0; i < 6; i++) {
    captcha += characters.charAt(Math.floor(Math.random() * characters.length));
  }
  return captcha;
}

使用方法:

const captcha = createCaptcha();
console.log(captcha); // 例如:'g7h3kD'

注意:

  • 此示例代码仅用于演示目的,您可能需要根据具体需求进行修改。
  • 建议使用更复杂的验证码生成算法,以提高安全性。
  • 您可以根据需要调整验证码的长度和字符集。
JavaScript 创建验证码函数 (createCaptcha())

原文地址: https://www.cveoy.top/t/topic/mVxT 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录