9.24java wab实现创建新界面验证码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | <!DOCTYPE html> <html> <head> <title>User Login</title> <style> .container { width: 300px; margin: 0 auto; padding: 20px; border: 1px solid #ccc; text-align: center; } .input- group { margin-bottom: 10px; } .input- group label { display: block; margin-bottom: 5px; } .input- group input { width: 100%; padding: 5px; } .input- group img { margin-top: 10px; } .input- group button { width: 100%; padding: 7px; background-color: #4CAF50; color: white; border: none; } </style> <script> function generateCaptcha() { var captcha = '' ; var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' ; var captchaLength = 4; for ( var i = 0; i < captchaLength; i++) { captcha += characters.charAt(Math.floor(Math.random() * characters.length)); } // Display the generated captcha document.getElementById( 'captcha' ).textContent = captcha; // Update the captcha image source with the generated captcha document.getElementById( 'captchaImage' ).src = 'https://dummyimage.com/150x50/000/fff&text=' + captcha; } function validateForm( event ) { event .preventDefault(); // Prevent form submission var captchaInput = document.getElementById( 'captchaInput' ).value; var captchaLabel = document.getElementById( 'captcha' ).textContent; if (captchaInput.toUpperCase() === captchaLabel.toUpperCase()) { // Correct captcha, perform actions for successful login alert( 'Login successful!' ); // Redirect to success page here // Clear form data document.getElementById( 'username' ).value = '' ; document.getElementById( 'password' ).value = '' ; document.getElementById( 'captchaInput' ).value = '' ; // Generate a new captcha generateCaptcha(); } else { // Incorrect captcha, show error message alert( 'Incorrect captcha!' ); // Clear captcha input document.getElementById( 'captchaInput' ).value = '' ; // Generate a new captcha generateCaptcha(); } } </script> </head> <body onload= "generateCaptcha()" > <div class = "container" > <h2>User Login</h2> <form action= "/login" method= "post" onsubmit= "validateForm(event)" > <div class = "input-group" > <label for = "username" >Username:</label> <input type= "text" id= "username" name= "username" required> </div> <div class = "input-group" > <label for = "password" >Password:</label> <input type= "password" id= "password" name= "password" required> </div> <div class = "input-group" > <label for = "captcha" >Captcha:</label> <input type= "text" id= "captchaInput" name= "captcha" required> <span id= "captcha" ></span> <img src= "" alt= "Captcha" id= "captchaImage" > <button type= "button" onclick= "generateCaptcha()" >Refresh</button> </div> <div class = "input-group" > <button type= "submit" >Login</button> </div> </form> </div> </body> </html> |
User Login
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异