This time I will bring you jquery's form verification submission, what are the precautions for jquery form verification submission, the following is a practical case, let's take a look.
Instructions:
1. The js script file path in the code needs to be replaced with your own directory file
2. Ajax is added to the code to verify whether the account exists
nbsp;html> <meta> <title>表单验证</title> <style> font { font-size: 10px; } .info { color: #AAAAAA; } .errormsg { color: #FF3030; } .errorinput { border-color: #FF3030; border-width: 1px; } .ok { color: #32CD32; } </style> <script></script> <script> //账号是否验证过 var accountIsChecked = false; var accountIsOK = false; var passwdIsOK = false; var confirmpwdIsOK = false; var phoneIsOK = false; $(function() { // 验证账号 $("#account").focus(function() { focus_checkaccount(); }).keyup( function() { $("#accountmsg").text("支持中文、字母、数字组合").removeClass() .addClass("info"); accountIsChecked = false; }).blur(function() { blur_checkaccount(); }) // 验证密码 $("#pwd").focus(function() { $("#pwdmsg").text("建议使用数字和字母的组合").removeClass().addClass("info"); }).blur(function() { blur_checkpwd(); blur_confirmpwd(); }); // 验证二次密码 $("#confirmpwd").focus(function() { $("#confirmmsg").text("请再次确认密码").removeClass().addClass("info"); }).blur(function() { blur_confirmpwd(); }); // 验证手机号码 $("#phone").focus(function() { $("#phonemsg").text("建议输入常用手机").removeClass().addClass("info"); }).blur(function() { blur_checkphone(); }) }); function focus_checkaccount() { if (!accountIsChecked) { $("#accountmsg").text("支持中文、字母、数字组合").removeClass() .addClass("info"); } } function blur_checkaccount() { var account = $("#account").val(); if (account != "") { // 判断account是否验证过 if (!accountIsChecked) { // 未验证过,则进行验证 ajax_checkaccount(account); } } else { $("#accountmsg").text(""); accountIsOK = false; } } // ajax请求验证account function ajax_checkaccount(account) { $.get("/airticleMgr/member", { m : "checkAccount", account : account }, function(data) { if ("true" == data) { $("#accountmsg").text("该账号已被注册").removeClass().addClass( "errormsg"); accountIsOK = false; } else { $("#accountmsg").text("√").removeClass().addClass("ok"); accountIsOK = true; } }); accountIsChecked = true; } function blur_checkpwd() { var lpwd = $("#pwd").val().length; if (lpwd > 0) { if (lpwd < 6) { $("#pwdmsg").text("长度在6-20位之间").removeClass().addClass( "errormsg"); passwdIsOK = false; } else { $("#pwdmsg").text("√").removeClass().addClass("ok"); passwdIsOK = true; } } else { $("#pwdmsg").text(""); passwdIsOK = false; } } function blur_confirmpwd() { var pwd = $("#pwd").val(); var confirmpwd = $("#confirmpwd").val(); if (confirmpwd != "") { if (confirmpwd == pwd) { $("#confirmmsg").text("√").removeClass().addClass("ok"); confirmpwdIsOK = true; } else { $("#confirmmsg").text("两次密码输入不一致").removeClass().addClass( "errormsg"); confirmpwdIsOK = false; } } else { $("#confirmmsg").text(""); confirmpwdIsOK = false; } } function blur_checkphone() { var phone = $("#phone").val(); var regix = /^1[34578][0-9]{9}$/; if (phone != "") { if (!regix.test(phone)) { $("#phonemsg").text("手机格式有误").removeClass() .addClass("errormsg"); phoneIsOK = false; } else { $("#phonemsg").text("√").removeClass().addClass("ok"); phoneIsOK = true; } } else { $("#phonemsg").text(""); phoneIsOK = false; } } // 表单验证 function check_form() { if (!accountIsOK) { if ($("#account").val() == "") { $("#accountmsg").text("请输入账号").removeClass().addClass( "errormsg"); } else { } return false; } if (!passwdIsOK) { if ($("#pwd").val() == "") { $("#pwdmsg").text("请输入密码").removeClass().addClass("errormsg"); } else { } return false; } if (!confirmpwdIsOK) { if ($("#confirmpwd").val() == "") { $("#confirmmsg").text("请再次输入密码").removeClass().addClass( "errormsg"); } else { } return false; } if (!phoneIsOK) { if ($("#phone").val() == "") { $("#phonemsg").text("请输入手机").removeClass().addClass("errormsg"); } else { } return false; } if (accountIsOK && passwdIsOK && confirmpwdIsOK && phoneIsOK) { alert("欢迎注册"); return true; } else { alert("请检查信息"); return false; } } </script> <h2 id="会员注册">会员注册</h2>
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!
Recommended reading:
The position of tr in the JQuery operation table
How to implement Jquery ajax asynchronous cross-domain
How does jquery plug-in print page content
The above is the detailed content of jquery form validation submission. For more information, please follow other related articles on the PHP Chinese website!

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

Node.js excels at efficient I/O, largely thanks to streams. Streams process data incrementally, avoiding memory overload—ideal for large files, network tasks, and real-time applications. Combining streams with TypeScript's type safety creates a powe

The differences in performance and efficiency between Python and JavaScript are mainly reflected in: 1) As an interpreted language, Python runs slowly but has high development efficiency and is suitable for rapid prototype development; 2) JavaScript is limited to single thread in the browser, but multi-threading and asynchronous I/O can be used to improve performance in Node.js, and both have advantages in actual projects.

JavaScript originated in 1995 and was created by Brandon Ike, and realized the language into C. 1.C language provides high performance and system-level programming capabilities for JavaScript. 2. JavaScript's memory management and performance optimization rely on C language. 3. The cross-platform feature of C language helps JavaScript run efficiently on different operating systems.

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver CS6
Visual web development tools

Atom editor mac version download
The most popular open source editor
