欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javascript和jquery實(shí)現(xiàn)用戶登錄驗(yàn)證

 更新時(shí)間:2022年03月25日 10:39:02   作者:尼阿卡  
這篇文章主要為大家詳細(xì)介紹了javascript和jquery分別實(shí)現(xiàn)用戶登錄驗(yàn)證的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

在上一篇文章Ajax實(shí)現(xiàn)異步用戶名驗(yàn)證功能中,用javascript實(shí)現(xiàn)了用戶驗(yàn)證,但并沒(méi)有對(duì)密碼進(jìn)行驗(yàn)證,這次追加了這個(gè)功能,并分別用javascript和jquery實(shí)現(xiàn)。

一.用jquery的ajax實(shí)現(xiàn)的關(guān)鍵代碼

實(shí)現(xiàn)如下

/*jquery實(shí)現(xiàn)
$(document).ready(function(){
 $("#account").blur(function(event) {
 $.ajax({
  type:"GET",
  url:"checkAccount.php?account="+$("#account").val(),
  dataTypes:"text",
  success:function(msg){
  $("#accountStatus").html(msg);
  },
  error:function(jqXHR) {
  alert("賬號(hào)發(fā)生錯(cuò)誤!")
  },
 });
 });
 
 $("#password").blur(function(event) {
 $.ajax({
  type:"GET",
  url:"checkPassword.php?",
  dataTypes:"text",
  data:"account="+$("#account").val()+"&password="+$("#password").val(),
  success:function(msg){
  $("#passwordStatus").html(msg);
  },
  error:function(jqXHR) {
  alert("密碼查詢發(fā)生錯(cuò)誤!")
  },
 });
 });
}); */

二.用javascript實(shí)現(xiàn)的關(guān)鍵代碼

實(shí)現(xiàn)如下

//javascript實(shí)現(xiàn)
 function checkAccount(){
 var xmlhttp;
 var name = document.getElementById("account").value;
 if (window.XMLHttpRequest)
  xmlhttp=new XMLHttpRequest();
 else
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 
 xmlhttp.open("GET","checkAccount.php?account="+name,true);
 xmlhttp.send();
 
 xmlhttp.onreadystatechange=function(){
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
  document.getElementById("accountStatus").innerHTML=xmlhttp.responseText;
 }
 }
 
 function checkPassword(){
 var xmlhttp;
 var name = document.getElementById("account").value;
 var pw = document.getElementById("password").value;
 if (window.XMLHttpRequest)
  xmlhttp=new XMLHttpRequest();
 else
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 
 xmlhttp.open("GET","checkPassword.php?account="+name+"&password="+pw,true);
 xmlhttp.send();
 
 xmlhttp.onreadystatechange=function(){
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
  document.getElementById("passwordStatus").innerHTML=xmlhttp.responseText;
 }
 }

mysql和數(shù)據(jù)庫(kù)部分跟上篇博文的一樣沒(méi)有改變,運(yùn)行結(jié)果如下圖

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助。

相關(guān)文章

最新評(píng)論