//用户登录层 (调用时须加入css)
function ShowLoginDiv() { //如果传入参数是 "1" 登录成功后刷新当前页面
var isRefresh=arguments[0];
$("#divLogin").remove();
$("#newDiv").remove();
$("body").append("
");
var divLogin = "
";
$("body").append(divLogin);
$("#imgCode").click(function() {
$(this).attr("src","../GetCode.aspx?id=" + Math.random() * 1000);
});
$("#btnCancal").click(function() {
$("#divLogin").remove();
$("#newDiv").remove();
$("#loginDiv").remove();
});
$("#loginDiv").find("div").eq(0).mousedown(function() {
DialogMouseDown("loginDiv");
});
$("#loginDiv").find("div").eq(0).get(0).onmouseup = function() {
DialogMouseUp();
};
$("#btnSubmit").click(function() {
var regUser = /^[0-9a-zA-Z._]{5,15}$/;
var regCode = /^[0-9a-zA-Z]{4}$/;
var userLogin = $.trim($("#txtUserLogin").val());
var userPass = $.trim($("#txtUserPass").val());
var code = $.trim($("#txtCode").val());
if (regUser.test(userLogin) == false || regUser.test(userPass) == false) {
alert("账号或者密码错误。。。");
return false;
}
if (regCode.test(code) == false) {
alert("验证码错误。。。");
return false;
}
$.ajax({
type: "post",
url: "../func/CheckUserLogin.ashx",
data: "typeId=2" + "&userId=" + userLogin + "&userPass=" + userPass + "&code=" + code,
cache: false,
success: function(result) {
if (result == "errorCode") {
alert("验证码错误。。。");
return false;
}
if (result == "loginError") {
alert("用户名或者密码错误。。。");
return false;
}
if (isRefresh == "1") {
alert("登录成功。。。");
window.location.href = document.URL;
return;
}
alert("登录成功,点击关闭。。。");
$("#divLogin").remove();
$("#newDiv").remove();
$("#loginDiv").remove();
}
});
});
}
var move_obj=null; //定义移动对象 实现div拖动效果
function DialogMouseDown(objId)
{
move_obj = document.getElementById(objId);
}
document.onmousemove = function(e) {
if (move_obj) {
e = window.event || e;
}
if (move_obj == null) {
return;
}
if (e.clientY >= 0 && e.clientX >= 0) {
move_obj.style.top = e.clientY + move_obj.offsetHeight / 2 - 3 + "px";
move_obj.style.left = e.clientX + "px";
}
}
function DialogMouseUp()
{
move_obj==null;
}
document.onmouseup = function() {
if (move_obj) {
move_obj = null;
}
}
下面代码是添加的背景层和显示登录的div css 可实现滑动时div跟着移动
#loginDiv /*全屏显示遮盖层里面的内容部分*/
{
position:fixed!important;
z-index:100;
position:absolute;
width:400px;
height:250px;
background-color:white;
top:50%;
left:50%;
margin-left:-200px!important;/*FF IE7 该值为本身宽的一半 */
margin-top:-130px!important;/*FF IE7 该值为本身高的一半*/
margin-top:0px;
_top: expression(eval(document.compatMode && document.compatMode=='CSS1Compat') ? documentElement.scrollTop +
(document.documentElement.clientHeight-this.offsetHeight)/2 : /*IE6*/ document.body.scrollTop + (document.body.clientHeight - this.clientHeight)/2);
}
#newDiv /*全屏显示的遮盖层*/
{
position:fixed!important;
position:absolute;top:0;left:0;
width:100%;height:100%;
background-color:#000;
opacity:0.3;
filter:alpha(opacity=30);
z-index:1;
_top: expression(eval(document.compatMode && document.compatMode=='CSS1Compat') ? documentElement.scrollTop +
(document.documentElement.clientHeight-this.offsetHeight)/2 : document.body.scrollTop + (document.body.clientHeight - this.clientHeight)/2);
}
这个是配合jquery ajax写的用户登录层