当前位置: 首页 > article >正文

js中随机生成4位数的验证码,要有字母和数字

代码:

function code(){
            let num1 = Math.floor(Math.random()*10)
            let num2 = Math.floor(Math.random()*10)
            let letter1 = String.fromCharCode(Math.floor(Math.random() * 26) + 97);
            let letter2 = String.fromCharCode(Math.floor(Math.random() * 26) + 65);
            var arr = [num1,num2,letter1,letter2]
            var str = "";
            for(var i=0;i<4;i++){
                str += arr[Math.floor(Math.random()*(arr.length))]
            }
            return str
        }
        document.write(code());

效果图:


http://www.kler.cn/news/367939.html

相关文章:

  • 破解API加密逆向接口分析,看这篇就够了
  • python源码编译—Cython隐藏源码(windows)
  • JAVA篇之类和对象
  • Flink CDC系列之:学习理解核心概念——Data Pipeline
  • Redis_写时复制(cow)
  • vscode配色主题与图标库推荐
  • 深入剖析反爬虫技术:挑战与应对
  • python--pyQt 单选按钮控件 -QRadioButton
  • Go编程语言介绍及项目案例
  • 从指定commit创建branch
  • 基于C#+Mysql实现(WinForm)停车场管理系统
  • 局部变量和全局变量(Python)
  • 【面试】RabbitMQ有哪些消息模型
  • 云岚到家 即刻体检 优惠卷管理 总结不熟练的点
  • 51c~目标检测~合集1
  • 循序渐进丨openGauss / MogDB 数据库内存占用相关SQL
  • 力扣每日一题打卡 684. 冗余连接
  • ReactNative TurboModule(3)
  • Spring Boot实战:构建全功能论坛平台
  • IllegalMonitorStateException:Illegal Monitor Operation 完美解决方法 ⚙️
  • 接口测试 —— Postman 变量了解一下!
  • Apache Commons Collections4 的详细指南
  • Android简单控件实现简易计算器
  • 详细且系统的Spring Boot应用开发
  • 还没想好说什么
  • 【负二进制】个人练习-Leetcode-1073. Adding Two Negabinary Numbers