加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

登录框一直在页面中间且使用Ajax无刷新登录

发布时间:2020-12-16 00:16:44 所属栏目:百科 来源:网络整理
导读:1.使用jQuery中的Ajax方法,提交信息到一般处理程序LoginHandler.ashx中进行验证处理 head runat="server" title无标题页/title script src="js/jquery-1.8.0.min.js" type="text/javascript"/script script type="text/javascript" $(function(){ $("#Butto

1.使用jQuery中的Ajax方法,提交信息到一般处理程序LoginHandler.ashx中进行验证处理

<head runat="server">

<title>无标题页</title>

<script src="js/jquery-1.8.0.min.js" type="text/javascript"></script>

<script type="text/javascript">
$(function(){

$("#Button1").click(function(){
var name=$("#Text_Account").val();
var pwd=$("#Text_Password").val();
if(name==""){
$("#Span1").css("color","red");
$("#Span1").html("用户名不能为空");
return;
}
if(pwd==""){
$("#Span2").css("color","red");
$("#Span2").html("密码不能为空");
return;
}
$.ajax({
type:"post",
url:"Ashx/LoginHandler.ashx",
data:({"name":name,"password":pwd}),
success:function(data){
alert(data);
}
})
});

$("#Button2").click(function(){
$("#div_login").css("display","block");
})
})




</script>


2.通过css样式控制显示的登录层始终在页面中间位置
<style type="text/css">
*
{
padding: 0px;
margin: 0px;
margin-right: 10px;
margin-bottom: 10px;
}
/*height与width 改成 100% 这里方便观看现象*/
body,html
{
height: 100%;
width: 100%;
}
html
{
overflow: hidden;
}
body
{
overflow-y: auto;
}
#div_login
{
position: absolute;
left: 50%;
top: 50%;
margin-left: -250PX;
margin-top: -150PX;
border: 1PX solid #F00;
}
</style>

</head>

<body>

<div>
<input type="button" id="Button2" value="显示登录" /></div>
<div id="div_login" style="display: none; padding-top: 100px; border: solid 1px green;
width: 400px; position: absolute; height: 300px; z-index: 9999">
姓名:<input type="text" id="Text_Account" /><span id="Span1"></span><br />
密码:<input type="password" id="Text_Password" /><span id="Span2"></span><br />
<input type="button" id="Button1" value="登录" />
</div>

</body>

</html>

3.ashx页面的处理程序省略,和常规的cs文件处理一样

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读