


Sharing an example of jQuery implementing a simple verification code function
This article mainly shares with you a simple verification code function based on jquery. The code is simple and easy to understand, very good, and has reference value. Friends who need it can refer to it. I hope it can help everyone.
In the process of learning jQuery, I wrote a simple small example of a verification code and recorded it for future reference. The source code is as follows:
<!DOCTYPE html> <html> <head> <title></title> <style type="text/css"> p{ background-color:blue; width:200px; height:100px; font-size:35px; } </style> <script src="../jquery-1.8.0.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { //我写的验证码 //验证码 var code; function createCode(){ code = '';//首先默认code为空字符串 var codeLength = 4;//设置长度,这里看需求,我这里设置了4 var codeV = $("p"); //设置随机字符 var random = new Array(0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R', 'S','T','U','V','W','X','Y','Z'); for(var i = 0; i < codeLength; i++){ //循环codeLength 我设置的4就是循环4次 var index = Math.floor(Math.random()*36); //设置随机数范围,这设置为0 ~ 36 code += random[index]; //字符串拼接 将每次随机的字符 进行拼接 } codeV.text(code);//将拼接好的字符串赋值给展示的Value } //页面开始加载验证码 createCode(); //验证码p加载点击事件 $("p").bind('click',function() { createCode(); }); //下面就是判断是否==的代码,无需解释 $("#b1").bind('click',function() { var oValue = $("#in1").val().toUpperCase(); $("#l1").html(""); if(oValue ==""){ $("#l1").html("<font color='red'>请输入验证码</font>"); }else if(oValue != code){ $("#l1").html("<font color='red'>验证码不正确,请重新输入</font>"); oValue = ""; createCode(); }else{ $("#l1").html("<font color='blue'>验证码正确</font>"); } }); }); </script> </head> <body> <center> <label >请输入验证码:</label><input type="text" id="in1" value="" placeholder="请输入验证码"> <button id="b1">点击验证</button> <p></p><label id="l1"></label> </center> </body> </html>
Related recommendations:
How to load the verification code function that comes with Yii
JS verification code function explanation
Detailed explanation of examples of implementing verification code function using JavaScript
The above is the detailed content of Sharing an example of jQuery implementing a simple verification code function. For more information, please follow other related articles on the PHP Chinese website!

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



1. After opening WeChat, click the search icon, enter WeChat team, and click the service below to enter. 2. After entering, click the self-service tool option in the lower left corner. 3. After clicking, in the options above, click the option of unblocking/appealing for auxiliary verification.

PHP8 is the latest version of PHP, bringing more convenience and functionality to programmers. This version has a special focus on security and performance, and one of the noteworthy new features is the addition of verification and signing capabilities. In this article, we'll take a closer look at these new features and their uses. Verification and signing are very important security concepts in computer science. They are often used to ensure that the data transmitted is complete and authentic. Verification and signatures become even more important when dealing with online transactions and sensitive information because if someone is able to tamper with the data, it could potentially

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

How to remove the height attribute of an element with jQuery? In front-end development, we often encounter the need to manipulate the height attributes of elements. Sometimes, we may need to dynamically change the height of an element, and sometimes we need to remove the height attribute of an element. This article will introduce how to use jQuery to remove the height attribute of an element and provide specific code examples. Before using jQuery to operate the height attribute, we first need to understand the height attribute in CSS. The height attribute is used to set the height of an element

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: <

Steam is a platform used by game enthusiasts. You can buy and purchase many games here. However, recently many users have been stuck in the mobile token verification interface when logging into Steam and cannot log in successfully. Faced with this Most users don't know how to solve this situation. It doesn't matter. Today's software tutorial is here to answer the questions for users. Friends in need can check out the operation methods. Steam mobile token error? Solution 1: For software problems, first find the steam software settings on the mobile phone, request assistance page, and confirm that the network using the device is running normally, click OK again, click Send SMS, you can receive the verification code on the mobile phone page, and you are done. Verify, resolve when processing a request

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute
