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
//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(){
var strUsetName = $("#userName").val();
//Get the password entered by the user
var strPassword = $("#password").val();
var msg=$("#msg");
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();
}