search
Homephp教程php手册php实战第七天

php实战第七天

Jun 13, 2016 am 10:57 AM
focusphpone timeeventActual combatSummarizepressfocusspecial effectsofget

 

 

 
 

 

 

 

总结一下学到的特效,获得焦点事件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();
  }


 

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor