Summarize the learned special effects to get the focus event. The focus event loses the focus event. blus presses a key event keypress.
[Javascript]/JavaScript Document
// Author QQ 496928838 blog http://wl.125.la
$ (Document). ready (function (e ){
// Obtain the user text box
Var userName = $ ("# userName ");
// Obtain the User Password box
Var password = $ ("# password ");
// Obtain the image before the text box
Var userimg = $ ("# userimg ");
// Obtain the image above the Password box
Var pwimg = $ ("# pwimg ");
// Focus the user text box
UserName. focus ();
// Bind the focus event of the user text box. If the focus event is lost, press an event.
UserName. focus (function (){
Userimg.css ("background-position", "0px ");
}). Blur (function (){
Userimg.css ("background-position", "-33px ");
}). Keypress (function (e ){
Var key = e. which;
If (key = 13 ){
Password. focus ();
}
});
// Bind the focus event of the Password text box. If the focus event is lost, press an event.
Password. focus (function (){
Pwimg.css ("background-position", "-66px ");
}). Blur (function (){
Pwimg.css ("background-position", "-99px ");
}). Keypress (function (e ){
Var key = e. which;
If (key = 13 ){
$ ("# Login"). click ();
}
});
// Bind the login button to click the event, move in the event, and remove the event
$ ("# Login"). click (function (){
// Obtain the user name
Var strUsetName = $ ("# userName"). val ();
// Obtain the password entered by the user
Var strPassword = $ ("# password"). val ();
Var msg = $ ("# msg ");
$. Ajax ({
Url: 'admin. php? M = admin & a = login ',
Type: 'post ',
DataType: 'json ',
Data :{
UserName: strUsetName,
Password: strPassword
},
Success: function (json ){
If (json. state = 'OK '){
Msg.html ("Login successful ");
} Else {
Msg.html (json. error );
}
}
});
}). Mousemove (function (){
Watermark (this).css ("background-position", "-138px ");
}). Mouseout (function (){
Watermark (this).css ("background-position", "0px ");
});
});
// JavaScript Document
// Author QQ 496928838 blog http://wl.125.la
$ (Document). ready (function (e ){
// Obtain the user text box
Var userName = $ ("# userName ");
// Obtain the User Password box
Var password = $ ("# password ");
// Obtain the image before the text box
Var userimg = $ ("# userimg ");
// Obtain the image above the Password box
Var pwimg = $ ("# pwimg ");
// Focus the user text box
UserName. focus ();
// Bind the focus event of the user text box. If the focus event is lost, press an event.
UserName. focus (function (){
Userimg.css ("background-position", "0px ");
}). Blur (function (){
Userimg.css ("background-position", "-33px ");
}). Keypress (function (e ){
Var key = e. which;
If (key = 13 ){
Password. focus ();
}
});
// Bind the focus event of the Password text box. If the focus event is lost, press an event.
Password. focus (function (){
Pwimg.css ("background-position", "-66px ");
}). Blur (function (){
Pwimg.css ("background-position", "-99px ");
}). Keypress (function (e ){
Var key = e. which;
If (key = 13 ){
$ ("# Login"). click ();
}
});
// Bind the login button to click the event, move in the event, and remove the event
$ ("# Login"). click (function (){
// Obtain the user name
Var strUsetName = $ ("# userName"). val ();
// Obtain the password entered by the user
Var strPassword = $ ("# password"). val ();
Var msg = $ ("# msg ");
$. Ajax ({
Url: 'admin. php? M = admin & a = login ',
Type: 'post ',
DataType: 'json ',
Data :{
UserName: strUsetName,
Password: strPassword
},
Success: function (json ){
If (json. state = 'OK '){
Msg.html ("Login successful ");
} Else {
Msg.html (json. error );
}
}
});
}). Mousemove (function (){
Watermark (this).css ("background-position", "-138px ");
}). Mouseout (function (){
Watermark (this).css ("background-position", "0px ");
});
});
Request ajax Method
[Php] public function login ()
{
$ Json ['state'] = 'no ';
If (! Empty ($ _ POST ['username']) &! Empty ($ _ POST ['Password']) {
$ UserName = $ _ POST ['username'];
$ Password = md5 ($ _ POST ['Password']);
/* Var_dumP ($ _ POST );
Var_dump ($ password );
Var_dump ($ password );*/
If ($ _ SESSION ['userdata'] = $ this-> db-> where ("userName = '{$ userName}' and password = '{$ password }'") -> fine ()){
$ Json ['state'] = 'OK ';
// Echo "<script> window. location. href = 'admin. php? M = admin & a = admin'; </script> ";
$ _ SESSION ['login'] = true;
} Else {
$ Json ['error'] = 'user does not exist or the password is incorrect ';
}
} Else {
$ Json ['error'] = 'enter your username and password ';
}
Echo json_encode ($ json );
// $ This-> display ();
}
Public function login ()
{
$ Json ['state'] = 'no ';
If (! Empty ($ _ POST ['username']) &! Empty ($ _ POST ['Password']) {
$ UserName = $ _ POST ['username'];
$ Password = md5 ($ _ POST ['Password']);
/* Var_dumP ($ _ POST );
Var_dump ($ password );
Var_dump ($ password );*/
If ($ _ SESSION ['userdata'] = $ this-> db-> where ("userName = '{$ userName}' and password = '{$ password }'") -> fine ()){
$ Json ['state'] = 'OK ';
// Echo "<script> window. location. href = 'admin. php? M = admin & a = admin'; </script> ";
$ _ SESSION ['login'] = true;
} Else {
$ Json ['error'] = 'user does not exist or the password is incorrect ';
}
} Else {
$ Json ['error'] = 'enter your username and password ';
}
Echo json_encode ($ json );
// $ This-> display ();
}