The seventh day of php practice_PHP tutorial

WBOY
Release: 2016-07-14 10:10:56
Original
949 people have browsed it


To summarize the special effects learned, get focus event focus, lose focus event blus press a certain key event keypress

[javascript] / JavaScript Document
// Author QQ 496928838 Blog http://wl.125.la
$(document).ready(function(e) {
//Get user text box
var userName=$("#userName");
//Get user password box
var password=$("#password");
//Get the picture in front of the text box
var userimg=$("#userimg");
//Get the picture in front of the password box
var pwimg=$("#pwimg");
       
//Give focus to the user text box
UserName.focus();
       
//Bind user text box focus event, lose focus event, press something 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 password text box focus event, lose focus event, press something 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 login button click event, move in event, move out event
$("#login").click(function(){
//Get user name
        var strUsetName = $("#userName").val();
//Get 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");
                                                                                                                                                                                            msg.html(json.error);                                                                                                                                                                                                                                                                                                                                                                      });
}).mousemove(function(){
​​​​ $(this).css("background-position","-138px");
}).mouseout(function(){
​​​​ $(this).css("background-position","0px");
});
                                   
       
});

// JavaScript Document
// Author QQ 496928838 Blog http://wl.125.la

$(document).ready(function(e) {

//Get user text box
var userName=$("#userName");
//Get user password box
var password=$("#password");
//Get the image in front of the text box
var userimg=$("#userimg");
//Get the picture in front of the password box
var pwimg=$("#pwimg");

//Give focus to the user text box
userName.focus();

//Bind user text box focus event, lose focus event, press something 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 password text box focus event, lose focus event, press something 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 login button click event, move in event, move out event
$("#login").click(function(){

//Get user name

var strUsetName = $("#userName").val();
//Get 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(){
$(this).css("background-position","-138px");
}).mouseout(function(){
$(this).css("background-position","0px");
});


});


Requested 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']='用户不存在或密码错误'; 
        } 
 
    }else { 
        $json['error']='请输入用户名和密码'; 
 
    }    
     
    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']='用户不存在或密码错误';
    }

   }else {
    $json['error']='请输入用户名和密码';

   } 
   
   echo json_encode($json);
   //$this->display();
  }


 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/477410.htmlTechArticle总结一下学到的特效,获得焦点事件focus 失去焦点事件 blus 按下某键事件 keypress [javascript] / JavaScript Document // 作者QQ 496928838 博客 http://wl....
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!