The seventh day of php practice

Source: Internet
Author: User

 

 

 
 

 

 

 

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 ();
}


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.