jQuery+ajax實(shí)現(xiàn)用戶(hù)登錄驗(yàn)證
本文實(shí)例為大家分享了jQuery+ajax實(shí)現(xiàn)用戶(hù)登錄驗(yàn)證的具體代碼,供大家參考,具體內(nèi)容如下
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>登錄界面</title> <style type="text/css"> *{ margin: 0; padding: 0; } h3{ display: block; width: 100%; height: 50px; text-align: center; line-height: 50px; background-color: cornflowerblue; cursor: move; } #login{ width: 500px; height: 270px; margin: 0 auto; position: absolute; top: 50%; left: 50%; margin-left: -250px; margin-top: -140px; border: 1px solid #6495ED; background-color: #FFFFFF; display: block; -moz-user-select: none; -ms-user-select: none; -webkit-user-select: none; } table{ margin-top: 50px; position: absolute; top: 50px; left: 0; width: 100%; height: 150px; text-align:center; } tr,td{ border: none; } tr{ height: 50px; } td{ padding: 0 5px 0 5px; } #bg{ width: 100%; height: 100%; background-color:rgba(0,0,0,0.2); position: absolute; top: 0; left: 0; } span{ width: 100px; height: 16px; display:block; margin-bottom: 12px; } body{ width: 100%; height: 100%; } .inpt{ width: 300px; height: 30px; outline: none; border: 1px solid darkturquoise; } .red{ color: red; font-size: 12px; } .btn{ outline: none; width: 60px; height: 25px; border: 1px solid #00CED1; } </style> <script src="js/jquery-3.5.1.min.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript"> $(function () { // 定義變量 var $mX; var $mY; var $move = false; // true是可以移動(dòng)登錄框 // 鼠標(biāo)按下事件 $("h3").mousedown(function (event) { $("#login").css("opacity",0.5); // 改變透明度 $move = true; // 得到鼠標(biāo)與登錄框原點(diǎn)之間的距離 $mX = event.pageX-parseInt($("#login").css("left")); $mY = event.pageY-parseInt($("#login").css("top")); }) // 鼠標(biāo)移動(dòng)事件 $(document).mousemove(function (event) { // 得到登錄框要移動(dòng)的量 var x = (event.pageX-$mX); var y = (event.pageY-$mY); console.log(x,y) if($move){ if(x>0&&y>0){ $("#login").css("left",x+"px") $("#login").css("top",y+"px") } } }).mouseup(function () { // 鼠標(biāo)彈起事件 $move = false; $("#login").css("opacity",1); }) // 異步請(qǐng)求 $(":submit").click(function () { $.ajax({ type:"get", url:"data.php", data:{"name":$("#user").val(),"password":$("#pwd").val()}, dataType:"json", success:function (data) { console.log("成功:",data); /*if (data.usermsg==1&&data.pwdmsg==1) { $(location).prop("href","index1.html"); } else{ $("span").text("用戶(hù)名或密碼錯(cuò)誤").prop("class","red"); }*/ if (data.usermsg==1&&data.pwdmsg==1) { $(location).prop("href","index1.html"); } else if(data.usermsg==0&&data.pwdmsg==0){ $("span").text("用戶(hù)名或密碼錯(cuò)誤").prop("class","red"); } else if(data.usermsg==0&&data.pwdmsg==1){ $("span").text("該用戶(hù)不存在").prop("class","red"); } else if(data.usermsg==1&&data.pwdmsg==0){ $("span").text("密碼錯(cuò)誤").prop("class","red"); } }, error:function (err) { console.log("失敗",err); } }) }) $(":reset").click(function () { $("span").text(""); }) }) </script> </head> <body> <div id="bg"></div> <form action="javascript:;" id="login" method="get"> <h3>歡迎登錄!</h3> <table border="0" cellspacing="0" cellpadding="0"> <tr> <td align="right">用戶(hù)名:</td> <td align="left"><input type="text" class="inpt" id="user" name="userName"/></td> </tr> <tr> <td align="right">密   碼:</td> <td align="left"><input type="password" class="inpt" id="pwd" name="pwd"/></td> </tr> <tr> <td align="center" colspan="2"> <span></span> <input type="submit" class="btn" value="提交"/>       <input type="reset" class="btn" value="重置"/> </td> </tr> </table> </form> </body> </html>
<?php $user="將軍"; $password="1234321"; $username=$_GET["name"]; $pwd=$_GET["password"]; $usermsg=0; $pwdmsg=0; if($user==$username){ $usermsg=1; } if($password==$pwd){ $pwdmsg=1; } echo json_encode(array("usermsg"=>$usermsg,"pwdmsg"=>$pwdmsg)); ?>
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>登錄成功頁(yè)面</title> </head> <body> <span id="" style="font-size: 60px;color: #008000;"> 登錄成功 </span> </body> </html>
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>登錄失敗頁(yè)面</title> </head> <body> <span id="" style="font-size: 60px;color: #FF0000;"> 登錄失敗 </span> </body> </html>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
jQuery實(shí)現(xiàn)可編輯的表格實(shí)例講解(2)
這篇文章主要內(nèi)容是JQuery實(shí)現(xiàn)可編輯的表格實(shí)例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2015-09-09jQuery實(shí)現(xiàn)鼠標(biāo)滾動(dòng)圖片延遲加載效果附源碼下載
本文給大家分享jquery技術(shù)實(shí)現(xiàn)圖片延時(shí)加載效果,本特效沒(méi)有使用專(zhuān)門(mén)的圖片延遲加載插件,只需要一小段jQuery代碼就實(shí)現(xiàn)了圖片延遲加載,使用非常方便,需要的朋友可以下載源碼2016-06-06JQuery中html()方法使用不當(dāng)帶來(lái)的陷阱
html方法當(dāng)不傳參數(shù)時(shí)用來(lái)獲取元素的html內(nèi)容2011-04-04用jQuery模擬頁(yè)面加載進(jìn)度條的實(shí)現(xiàn)代碼
因?yàn)槲覀儫o(wú)法通過(guò)任何方法獲取整個(gè)頁(yè)面的大小和當(dāng)前加載了多少,所以想制作一個(gè)加載進(jìn)度條的唯一辦法就是模擬。那要怎么模擬呢2011-12-12自動(dòng)設(shè)置iframe大小的jQuery代碼
自動(dòng)設(shè)置iframe的寬度在應(yīng)用中還是比較廣泛的,本文使用jquery實(shí)現(xiàn)一下,感興趣的朋友可以參考下2013-09-09給jqGrid數(shù)據(jù)行添加修改和刪除操作鏈接(之一)
我這里用的不是jqGrid的自帶的編輯和刪除操作,我已經(jīng)把分頁(yè)導(dǎo)航欄下的編輯,刪除,搜索都取消掉了2011-11-11jquery獲取復(fù)選框checkbox的值實(shí)現(xiàn)方法
下面小編就為大家?guī)?lái)一篇jquery獲取復(fù)選框checkbox的值實(shí)現(xiàn)方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-05-05jQuery幫助之篩選查找 children([expr])
取得一個(gè)包含匹配的元素集合中每一個(gè)元素的所有子元素的元素集合。2011-01-01