⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 login.js

📁 1
💻 JS
字号:

var xmlHttp; 
var tip;

//用于创建XMLHttpRequest对象
function createXmlHttp() {
    //根据window.XMLHttpRequest对象是否存在使用不同的创建方式
    if (window.XMLHttpRequest) {
       xmlHttp = new XMLHttpRequest();                  //FireFox、Opera等浏览器支持的创建方式
    } else {
       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");//IE浏览器支持的创建方式
    }
}

function G(id){
    return document.getElementById(id);
};
function GC(t){
   return document.createElement(t);
};
String.prototype.trim = function(){
          return this.replace(/(^\s*)|(\s*$)/g, '');
};
function isIE(){
      return (document.all && window.ActiveXObject && !window.opera) ? true : false;
} 
     var loginDivWidth = 250;
var sign_in_flow = 
	'<div class="x-box-ml">'+
    '<div class="x-box-mr">'+
    '<div class="x-box-mc">'+
'<h3 style="margin-bottom:5px;">管理员登录</h3>'+
'<div>用户名:<input type="text" id="username" maxlength="64" size="25"/></div>'+
'<div>密&nbsp;&nbsp;&nbsp;码:<input type="password" id="sign_pwd" size="25"/></div>'+

'<input type="button" value="登录" onclick="signFlow(1);" id="sign_button"/>'+
'<input type="button" value="取消" onclick="cancelSign();"/>'+
'</div></div></div>';

function cancelSign(){
    G("sign_div").style.display = 'none';
    G("cover_div").style.display = 'none';
   document.body.style.overflow = '';
};

function checkEmail(){
   if(G("username").value.trim() == ''){
    return '<div style="color:#FF0000";">用户名不能为空.</div>';
   }
   return '';
}
function checkPwd(){
   if(G("sign_pwd").value.trim() == ''){
    return '<div style="color:#FF0000";">密码不可以为空.</div>';
   }
   return '';
}

function signFlow(isSignIn){
    var error = checkEmail();
    var htmlText = null;
    if (isSignIn == 1) {
     if (error == ''){
      error = checkPwd();
     }
	 if (error == ''){
		 
	login(G("username").value.trim(),G("sign_pwd").value.trim());	 
	
	
	if(this.tip!=1 || this.tip.equals('1')){
			error='<div style="color:#FF0000";">用户名或密码错误.</div>';
	}
	
	}
     htmlText = sign_in_flow;
    }
    var username = G("username").value.trim();

   if (error == '') {
	} else {
    G("sign_div").innerHTML = error + htmlText;
    G("username").value = username; 
	error='';
    }
	
};
function popCoverDiv(){
   if (G("cover_div")) {
    G("cover_div").style.display = '';
   } else {
    var coverDiv = GC('div');
    document.body.appendChild(coverDiv);
    coverDiv.id = 'cover_div';
    with(coverDiv.style) {
     position = 'absolute';
     background = '#CCCCCC';
     left = '0px';
     top = '0px';
     var bodySize = getBodySize();
     width = bodySize[0] + 'px'
     height = bodySize[1] + 'px';
     zIndex = 98;
     if (isIE()) {
      filter = "Alpha(Opacity=60)";
     } else {
      opacity = 0.6;
     }
    }
   }
}
function getBodySize(){
   var bodySize = [];
   with(document.documentElement) {
    bodySize[0] = (scrollWidth>clientWidth)?scrollWidth:clientWidth;
    bodySize[1] = (scrollHeight>clientHeight)?scrollHeight:clientHeight;
   }
   return bodySize;
} 
function popSign(isLogin){
   if (G("sign_div")) {
    G("sign_div").style.display = '';
   } else {
    var signDiv = GC('div');
    document.body.appendChild(signDiv);
    signDiv.id = 'sign_div';
    signDiv.align = "center";
    signDiv.onkeypress = function(evt){
          var e = window.event?window.event:evt;
          if (e.keyCode==13 || e.which==13) {
           if (G("sign_button")) {
            G("sign_div").focus();
            G("sign_button").click();
           }
          }
         };
    with (signDiv.style) {
     position = 'absolute';
     //left = (document.documentElement.clientWidth - loginDivWidth)/2 +250+ 'px';
    // top = (document.documentElement.clientHeight - 300)/2 +250+ 'px';
	 
	 left = 300+ 'px';
     top = 190+ 'px';
     width = loginDivWidth + 'px';
     zIndex = 99;
     background = '#FFFFFF';
     border = '#66CCFF solid 1px';
    }
   }
   if(isLogin) {
    G("sign_div").innerHTML = sign_in_flow;
   } 
}
function popSignFlow(isLogin) {
   popCoverDiv();  
   popSign(isLogin);  
   document.body.style.overflow = "hidden";
   G("username").focus();
}

//获取查询登陆回调函数
function loginPostCallBack() {
		if (xmlHttp.readyState == 4) {
        	this.tip=(xmlHttp.responseText).trim();
	    	if(this.tip==1)
	   			location='admin/index.jsp';
			this.tip==0;
    	}
    
}

//登陆函数
function login(username,password){
        createXmlHttp();                                    //创建XMLHttpRequest对象
        xmlHttp.onreadystatechange = loginPostCallBack;    //设置回调函数
        xmlHttp.open("POST", "admin/login.jsp", true);         //发送POST请求
        //设置POST请求体类型
        xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        xmlHttp.send("username=" + username.trim()+"&password=" + password.trim());//发送包参数的请求体
		
		
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -