技术栈

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

y先森2024-10-23 23:55

代码:

javascript 复制代码
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());

效果图:

上一篇:connect 的断线重连设计
下一篇:虾皮一面-2
相关推荐
冬奇Lab
8 分钟前
AI Workflow 定义的四次演进:从 Markdown 到 JS 脚本,再到分布式多 Agent
javascript·人工智能·agent
zhangxingchao
17 分钟前
Kotlin常用的Flow 操作符整理
前端
IT_陈寒
2 小时前
React的useState居然还有这种坑?我差点删库跑路
前端·人工智能·后端
Pedantic
3 小时前
SwiftUI 手势笔记
前端·后端
橙子家
3 小时前
浏览器缓存之【结构化数据库与缓存】: IndexedDB、Cache storage 和 Storage buckets
前端
user2058556151813
4 小时前
X6 中边悬浮置顶,规避 `mouseleave` 事件丢失问题
前端
李明卫杭州
4 小时前
CSS aspect-ratio 属性完全指南
前端
Pedantic
5 小时前
SwiftUI 手势层级(Gesture Hierarchy)详解
前端
飘尘
6 小时前
前端转型全栈(Java后端)的快速上手指引
前端·后端·全栈
热门推荐
012026年6月AI行业全景:从百模大战到Agent元年,这30天发生了什么?022026年6月AI大模型全景报告:GPT-5.6、Claude Opus 4.8、Gemini 3.5,中美AI三足鼎立谁主沉浮?032026 年 AI 编程工具终极横评:Cursor vs Claude Code vs Copilot vs Windsurf04【AI】2026 年具身智能模型和世界模型总结05GitHub 镜像站点06AI科技热点日报 | 2026年6月1日07AI一周事件 · 2026-06-03 至 2026-06-09082026 AI 编程工具终极实战指南:Cursor vs Claude Code vs Copilot,开发者该怎么选?09Claude Code、Codex、Cursor三分天下:2026年AI编程Agent生态全景剖析10上线仅72小时被强制下架:Claude Fable 5 的短命