Home > php教程 > php手册 > body text

php实战第七天

WBOY
Release: 2016-06-13 10:57:15
Original
1191 people have browsed it

 

 

 
 

 

 

 

总结一下学到的特效,获得焦点事件focus 失去焦点事件 blus 按下某键事件 keypress

 

 

[javascript] / JavaScript Document  
// 作者QQ 496928838 博客 http://wl.125.la   
$(document).ready(function(e) { 
    //获取用户文本框  
    var userName=$("#userName"); 
    //获取用户密码框  
    var password=$("#password"); 
    //获取文本框前面图片  
    var userimg=$("#userimg"); 
    //获取密码框前面图片  
    var pwimg=$("#pwimg"); 
     
    //给用户文本框置焦点  
    userName.focus(); 
     
    //绑定用户文本框焦点事件,失去焦点事件,按下某件事件  
    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(); 
        } 
    }); 
     
    //绑定密码文本框焦点事件,失去焦点事件,按下某件事件  
    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(); 
        } 
    }); 
 
    //绑定登陆按钮点击事件,移入事件,移出事件  
    $("#login").click(function(){ 
        //获取用户名称  
        var strUsetName = $("#userName").val(); 
        //获取用户输入密码  
        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("登陆成功"); 
                }else{ 
                    msg.html(json.error);    
                } 
            } 
             
        }); 
    }).mousemove(function(){ 
        $(this).css("background-position","-138px"); 
    }).mouseout(function(){ 
        $(this).css("background-position","0px"); 
    }); 
         
     
}); 

// JavaScript Document
// 作者QQ 496928838 博客 http://wl.125.la
$(document).ready(function(e) {
 //获取用户文本框
 var userName=$("#userName");
 //获取用户密码框
 var password=$("#password");
 //获取文本框前面图片
 var userimg=$("#userimg");
 //获取密码框前面图片
 var pwimg=$("#pwimg");
 
 //给用户文本框置焦点
 userName.focus();
 
 //绑定用户文本框焦点事件,失去焦点事件,按下某件事件
 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();
  }
 });
 
 //绑定密码文本框焦点事件,失去焦点事件,按下某件事件
 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();
  }
 });

 //绑定登陆按钮点击事件,移入事件,移出事件
    $("#login").click(function(){
  //获取用户名称
  var strUsetName = $("#userName").val();
  //获取用户输入密码
  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("登陆成功");
    }else{
     msg.html(json.error); 
    }
   }
   
  });
 }).mousemove(function(){
  $(this).css("background-position","-138px");
 }).mouseout(function(){
  $(this).css("background-position","0px");
 });
  
 
});


请求的ajax方法


[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=&#39;admin.php?m=admin&a=admin&#39;;</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=&#39;admin.php?m=admin&a=admin&#39;;</script>";
     $_SESSION['login']=true;
     
    }else{

     $json['error']='用户不存在或密码错误';
    }

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

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


 

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template