


jquery.cookie.js method to implement user login and save password function_jquery
The example in this article describes how jquery.cookie.js implements the function of saving passwords for user login. Share it with everyone for your reference, the details are as follows:
The js that need to be imported are jquery.js and jquery.cookie.js
<script type="text/javascript" src=" jquery-1.5.2.js"></script> <script type="text/javascript" src="jquery.cookie.js"></script>
When the page loads, first try to get the value of the cookie. If the cookie has a value, fill the obtained value into the input box and select the check box to save the password
jQuery(function(){ //获取cookie的值 var username = $.cookie('username'); var password = $.cookie('password'); //将获取的值填充入输入框中 $('#uName').val(username); $('#psw').val(password); if(username != null && username != '' && password != null && password != ''){//选中保存秘密的复选框 $("#remember_password").attr('checked',true); } });
Determine whether the save password checkbox is selected when logging in. If it is selected, create a cookie (the validity period can be decided by yourself. The cookie below is valid for 7 days). If it is not selected, delete the cookie (because it may have been saved last time). Password, choose to cancel saving the password for this login, so you need to delete the cookie so that the cookie will have no value when you log in next time).
Pay special attention to the operation of deleting cookies. Many articles on the Internet use the method $.cookie('username',null), but it does not work when I use this method. The cookie exists every time I log in again. I try to use $.cookie ('username','') still has problems, the program becomes unable to save passwords.
//提交表单的处理函数 function Login() { var uName =$('#uName').val(); var psw = $('#psw').val(); if($('#remember_password').attr('checked') == true){//保存密码 $.cookie('username',uName, {expires:7,path:'/'}); $.cookie('password',psw, {expires:7,path:'/'}); }else{//删除cookie $.cookie('username', '', { expires: -1, path: '/' }); $.cookie('password', '', { expires: -1, path: '/' }); } //.... //提交表单的操作 }
Save password checkbox on login page
<input type="checkbox" name="remember_password" id="remember_password"/> <span id="span_tip" style="margin-bottom:-2px;color:white;font-size:12px;">记住密码 </span>
PS: Here we recommend a very easy-to-use JavaScript compression, formatting and encryption tool, which is very powerful (for those who want to encrypt their code, you may want to try it Try the js encryption function here):
JavaScript compression/formatting/encryption tool: http://tools.jb51.net/code/jscompress
In addition, the encryption in the above js tool uses the eval function encryption form. For this, this site also provides the following decryption tool for eval function encryption, which is very powerful and practical!
JS eval method online encryption and decryption tool: http://tools.jb51.net/password/evalencode
Readers who are interested in more jQuery-related content can check out the special topics on this site: "JQuery cookie operation skills summary", "jQuery table (table) operation skills summary" , "Summary of jQuery drag effects and techniques", "Summary of jQuery extension techniques", "Summary of jQuery common classic special effects", "jQuery animation and special effects usage summary", "jquery selector usage summary" and "jQuery common plug-ins and usage summary"
I hope this article will be helpful to everyone in jQuery programming.

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



PHP development skills: How to implement user login restriction function In website or application development, user login restriction function is a very important security measure. By limiting the number of login attempts and frequency of users, you can effectively prevent accounts from being maliciously cracked or brute force cracked. This article will introduce how to use PHP to implement user login restriction function and provide specific code examples. 1. Requirements analysis of user login restriction function User login restriction function usually includes the following requirements: Limitation on the number of login attempts: when the user continuously inputs errors

How to send SMS verification codes and email notifications when users log in in PHP. With the rapid development of the Internet, more and more applications require user login functions to ensure security and personalized experience. In addition to basic account and password verification, in order to improve user experience and security, many applications will also send mobile phone SMS verification codes and email notifications when users log in. This article will describe how to implement this functionality in PHP and provide corresponding code examples. 1. Send SMS verification code 1. First, you need someone who can send SMS

How to use PHP and CGI to implement user registration and login functions User registration and login are one of the necessary functions for many websites. In this article, we will introduce how to use PHP and CGI to achieve these two functions. We'll demonstrate the entire process with a code example. 1. Implementation of the user registration function The user registration function allows new users to create an account and save their information to the database. The following is a code example to implement the user registration function: Create a database table First, we need to create a database table to store user information. Can

How to use Elasticsearch and PHP to build a user login and permission management system Introduction: In the current Internet era, user login and permission management are one of the necessary functions for every website or application. Elasticsearch is a powerful and flexible full-text search engine, while PHP is a widely used server-side scripting language. This article will introduce how to combine Elasticsearch and PHP to build a simple user login and permission management system

UniApp implements detailed analysis of user login and authorization. In modern mobile application development, user login and authorization are essential functions. As a cross-platform development framework, UniApp provides a convenient way to implement user login and authorization. This article will explore the details of user login and authorization in UniApp, and attach corresponding code examples. 1. Implementation of user login function Create login page User login function usually requires a login page, which contains a form for users to enter their account number and password and a login button

How to use PHP arrays to implement user login and permission management functions When developing a website, user login and permission management are one of the very important functions. User login allows us to authenticate users and protect the security of the website. Permission management can control users' operating permissions on the website to ensure that users can only access the functions for which they are authorized. In this article, we will introduce how to use PHP arrays to implement user login and permission management functions. We'll use a simple example to demonstrate this process. First we need to create

Introduction to the method of using sessions to implement user login and logout in the Slim framework: Sessions are a technology commonly used in web applications. It can be used to store and manage user-related data, such as the user's login status. wait. As a lightweight PHP framework, the Slim framework provides a simple API to handle sessions. This article will introduce how to use sessions in the Slim framework to implement user login and logout functions. To install the Slim framework first, we need to

How to use PHP to implement user registration/login function of CMS system? With the development of the Internet, the CMS (Content Management System) system has become a very important part of website development. The user registration/login function is an indispensable part. This article will introduce how to use PHP language to implement the user registration/login function of the CMS system, and attach corresponding code examples. The following are the implementation steps: Create a user database First, we need to create a
