国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

用戶注冊(cè)檢測(cè)用戶名是否存在ajax+php代碼

2024-05-04 21:58:26
字體:
供稿:網(wǎng)友

在用戶注冊(cè)檢測(cè)用戶名是否存在我們要提供告訴用戶你要注冊(cè)的用戶名是否可用,那么我們就得利用ajax技術(shù)來實(shí)例,下面是一款ajax php當(dāng)用戶輸入完用戶名時(shí)提示用戶是否可用用的代碼:

  1. <?php 
  2. $title = isset($_get['title'])?$_get['title']:''
  3. if$title ) 
  4.  $sql ='select id from filecontent where title=''.$title.'''
  5.  $q = mysql_query( $sql ) or die( mysql_error()); 
  6.  if( mysql_num_rows( $q )  ) 
  7.  { 
  8.   echo 1; 
  9.  } 
  10.  else 
  11.  { 
  12.   echo 0; 
  13.  } 
  14. else 
  15.  echo 0;//開源代碼Vevb.com 
  16. ?> 
  17.  
  18. <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"
  19. <html xmlns="http://www.111cn.net/1999/xhtml"
  20. <head> 
  21. <meta http-equiv="content-type" content="text/html; charset=gb2312" /> 
  22. <title> 用戶注冊(cè)檢測(cè)用戶名是否存在ajax + php代碼</title> 
  23. <script> 
  24. //  用戶注冊(cè)檢測(cè)用戶名是否存在ajax + php代碼 
  25.  
  26.  
  27. function createxmlhttprequest(){//創(chuàng)建xmlhttprequest對(duì)象 
  28.  if(window.activexobject){//ie 
  29.   try { 
  30.    return new activexobject("microsoft.xmlhttp"); 
  31.   } catch(e){ 
  32.    return
  33.   } 
  34.  }else if(window.xmlhttprequest){//mozilla,firefox 
  35.   try { 
  36.    return new xmlhttprequest(); 
  37.   } catch(e){ 
  38.    return
  39.   } 
  40.  } 
  41.  
  42. function getrenews(value){//主調(diào)函數(shù) 
  43.  var xmlhttp=createxmlhttprequest(); 
  44.  var url = "t.php?action=check&title="+value+"&mt="+math.random(300000); 
  45.  if (value==""){   
  46.   return false ; 
  47.  } 
  48.  if (xmlhttp){ 
  49.   callback = getreadystatehandler(xmlhttp); 
  50.   xmlhttp.onreadystatechange = callback; 
  51.   xmlhttp.open("get", url,true); 
  52.   xmlhttp.send(null); 
  53.  } 
  54. //返回0代表用戶名可用,否則提示己被注冊(cè)。 
  55.  
  56. function getreadystatehandler(xmlhttp){//服務(wù)器返回后處理函數(shù) 
  57.  return function (){ 
  58.   if(xmlhttp.readystate == 4){ 
  59.    if(xmlhttp.status == 200){ 
  60.         
  61.       
  62.      if (xmlhttp.responsetext==1){ 
  63.        document.getelementbyid("checkid").innerhtml="<font color='red'>對(duì)不起,你輸入的用戶名己被注冊(cè)!</font>";      
  64.      }else
  65.       document.getelementbyid("checkid").innerhtml="可以注冊(cè)";      
  66.      }       
  67.    } 
  68.   } 
  69.  } 
  70. </script> 
  71. </head> 
  72.  
  73. <body> 
  74. 給input框增加onblur事件,當(dāng)用戶輸入完用戶名就檢測(cè)用戶名,并給出提示。 
  75. 輸入用戶名<input name="title" type="text" id="title" size="40" onblur="getrenews(this.value);"><span id="checkid"></span> 
  76. </body> 
  77. </html> 

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 尼玛县| 元朗区| 金塔县| 神农架林区| 米泉市| 乌恰县| 资兴市| 乌鲁木齐县| 日照市| 神池县| 贵州省| 靖远县| 玉门市| 开远市| 西青区| 文昌市| 平顺县| 海门市| 永胜县| 大邑县| 乌苏市| 英德市| 浙江省| 涪陵区| 灌云县| 怀柔区| 鄢陵县| 白山市| 封开县| 湛江市| 改则县| 海淀区| 绵阳市| 海原县| 讷河市| 获嘉县| 孙吴县| 富阳市| 上栗县| 巴塘县| 慈利县|