


Implementation code of login page using Jquery to create the best user experience_jquery
The following operations default to the client server and enable js support. If there is no script, please write your own code to implement it
First paste the display picture:
Default status:
Error status:
Waiting status:
Workflow:
Before the user logs in and submits, only the null value and length are judged in the client verification input box. After submitting to the server, the submitted string is automatically verified for legality and length and illegal characters are removed to return a legal string. Login verification is performed based on the returned legal string, and then json data is returned to the front desk for processing. The successful login mark is loginSuccess=0. After the server returns the data, all work is handed over to the front desk for processing.
Here we focus on the front-end processing process.
First let the page get focus after it is opened:
$('body').focus(); This way the mouse focus will not appear in the input box.
Then handle the acquisition and focus-losing events of the two input boxes:
$('.reg-action .reg-input').each(function () {
var items = $(this).parent('.reg-item');
if ($(this).val()) {
items.addClass("focus");
}
$(this).bind('focus blur', function (event) {
var type = event.type; //Get event type
if (type == 'focus') {
if (items.hasClass('error')) {
$(this).val( "");
items.removeClass('error');
}
items.addClass('focus');
} else if (!$(this).val()) {
items.removeClass('focus');
}
})
});
After the submit button:
$(".btn-submit").click(function () {
var wrongTypeName = 0,//The error type of the user name can be directly used as the subscript of the error message array
wrongTypePwd = 0,//Wrong type of user password
uname = $("#uname").val(),//Username
pwd = $("#passwd").val(), //User password
plength = pwd.length,
nlength = uname.length,//Length
wrongNameHtml = new Array("", "Please enter the user name", "The user name is too short" , "The username is longer than 12 characters", "Your username or password is wrong", "Timeout, please log in again"),
wrongPwdHtml = new Array("", "Please enter the password", "The password length is less than 6 digits", "Password length exceeds 20 digits", "Password contains illegal characters");
//What is defined here is an array of error messages
if (nlength == 0) {
wrongTypeName = 1;
}
if (nlength > 0 && nlength wrongTypeName = 2;
}
if (nlength > 20) {
wrongTypeName = 3;
}
if (plength == 0) {
wrongTypePwd = 1;//This is a judgment on the length of the username and password, and obtains the subscript of the error message array } else {
var patrn = /^(w){6,20}$/;
if (plength wrongTypePwd = 2;
if (plength > 20)
wrongTypePwd = 3;
if (plength > 6 && plength if (!patrn.exec(pwd))
wrongTypePwd = 4; //Here is the user password Front-end judgment of legality and returns the subscript of the error array
}
}
var inputTip = function (index, tipHtml, tipNum) {
$(".reg-tip" ).eq(index).html(tipHtml[tipNum]);
if (tipNum > 0)
$(".reg-item").eq(index).addClass("error");
else
$(".reg-item").eq(index).removeClass("error");
}//Define the error message page display function. Since there are only two input boxes on the page, I directly specify the index here. If there are many on the page, you can use $(this).index()
inputTip(0, wrongNameHtml, wrongTypeName);
inputTip (1, wrongPwdHtml, wrongTypePwd);
if (wrongTypePwd == 0 && wrongTypeName == 0) {//When the user input information is completely legal, that is, the array subscripts are all 0, start ajax verification
//$(".reg-input").attr('disabled', true);
$("#login-form input").attr('disabled', true);
$('.remember').unbind('click');
$(".btn-master").addClass("visibility");
//The information has been submitted to the server, so the page All input box buttons are set to a disabled state, which can effectively avoid repeated submissions
var $params = "username=" uname "&password=" pwd "&remember=" $('#remember-long'). val();
//alert($params);
$.ajax({
url: "CheckUserLogin.aspx",
data: $params,
dataType: "json" ,
success: function (data) {
$(data).each(function (te, u) {
wrongTypeName = u.wrongTypeName;
wrongTypePwd = u.wrongTypePwd;
var loginSuccess = u.loginSuccess;//Get the json data returned by the server
//alert(wrongTypeName);
//alert(wrongTypePwd);
if (loginSuccess == 0) {
location. href = "/Members/Memb.html";//Jump directly if successful
} else {//Failed to log in, return friendly prompt message
$(".btn-master").removeClass(" visibility");
$("#login-form input").attr('disabled', false);
inputTip(0, wrongNameHtml, wrongTypeName);
inputTip(1, wrongPwdHtml, wrongTypePwd) ;
}
});
},
error: function () {//If an ajax request error occurs, a timeout is returned and retry.
wrongTypeName = 5;
inputTip(0, wrongNameHtml, wrongTypeName);
$("#login-form input").attr('disabled', false);
$('.remember ').bind('click', function () { checkClick(); });
$(".btn-master").removeClass("visibility");
}
});
}
});
if ($('#remember-long').attr('checked') == "checked") {
$('#remember-long').attr('checked', false);
$('#remember-long').val("0")
}
else {
$('#remember-long').attr('checked', true);
$('#remember-long').val("1")
}
}
$('.remember').bind('click', function () { checkClick(); });
$("#remember-long").click(function () { checkClick(); });
//Remember the binding of the login checkbox and label click. Here we only write cookies without login processing.
//The idea of login processing is to directly read the data in cookies and submit it to the background when selected.
//Since the password recorded in cookies is encrypted, To append the password has been encrypted
$(document).bind('keydown', 'return', function(){$(".btn-submit").trigger('click');});
// Bind the Enter event of the keyboard
Help Microsoft eliminate IE6.0
if ($.browser.msie && $.browser.version == "6.0") {
//Help Microsoft eliminate ie6
if ($.cookie('masterShow ') != "hidden")
$('body').append('
Your browser isIE6.0> ;, there are many vulnerabilities and the user experience is poor. Microsoft official will give up support. For the sake of your own computer security and the best user experience, it is recommended that you upgrade to IE8.0or above or useFirefoxBrowser
div>$(".master").delay(1000).slideDown('', function () {
$(".m-close").fadeIn();
}) ;
$(".m-close-short").click(function () {
$(".m-close").fadeOut('', function () {
$(" .master").slideUp();
});
});
$(".m-close-long").click(function () {
$(".m -close").fadeOut('', function () {
$(".master").slideUp();
$.cookie('masterShow', 'hidden');
}) ;
});
}
About the page, this login page plagiarizes the design of a previous version of Diandian.com. Diandian uses the kissy library to send back to the server for verification every time, and the entire page To refresh, I switched to using jquery to use ajax asynchronous verification, and set the page elements to be unavailable during the verification process to prevent repeated logins.
Full file package download: jquery_login.rar
Author: Ethan.zhu

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.


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

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1
Powerful PHP integrated development environment