想实现在文本框录入后就校验出值是否在数据库中的表中存在,不要等到提交的时候才判断,如何写,如果不行,怎么写能简单呢,要代码哦

解决方案 »

  1.   

    ajax把录入的文本传递到后台查数据库进行验证,如已存在则在页面上进行提示。
      

  2.   

    <script language="javascript" type="text/javascript">
    var xmlHttp = false;
    try {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e2) {
        xmlHttp = false;
      }
    }
    if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
      xmlHttp = new XMLHttpRequest();
    }function callServer() {
      var u_name = document.getElementById("u_name").value;
      if ((u_name == null) || (u_name == "")) return;
      var url = "cu.asp?name=" + escape(u_name);
      xmlHttp.open("GET", url, true);
      xmlHttp.onreadystatechange = updatePage;
      xmlHttp.send(null);  
    }function updatePage() {
      if (xmlHttp.readyState < 4) {
     emailts.innerHTML="系统将自动检测您的用户名是否已被注册,请稍候...";
      }
      if (xmlHttp.readyState == 4) {
        var response = xmlHttp.responseText;
      if (response=="true"){
       emailts.innerHTML='恭喜你,用户名还未被注册!';
       emailts.className="showok";   
      }
      else{
      emailts.innerHTML='对不起,用户名已被注册!';
      emailts.className="showno";
      }  
      }
    }
    </script>
    <style type="text/css">
    <!--
    .showno {
     color: #FF0000;
     font-weight: bold;
     background:url("note_error.gif") no-repeat 12px center;
     padding-left:35px;
      
    }
    .showok {
     color: #FF0000;
     font-weight: bold;
     background:url("note_ok.gif") no-repeat 12px center;
     padding-left:35px;
      
    }
    -->
    </style>
    </head><body>
    <table cellspacing="0" cellpadding="0" width="694" border="0">
      <tbody>
        <tr>
          <td width="179" height="40" align="right" class="F14">用户名:</td>
          <td width="168"><input id="u_name"  onChange="callServer();"  style="WIDTH: 155px" />
        </td>
          <td width="347"> <div id="emailts"></div></td>
        </tr>
        <tr>
          <td height="40" align="right" class="F14">Email地址:</td>
          <td colspan="2"><input id="email"   style="WIDTH: 155px" />     </td>
        </tr> 
      </tbody>
    </table>   cu.asp<%
    Response.Buffer = True 
    Response.ExpiresAbsolute = Now() - 1 
    Response.Expires = 0 
    Response.CacheControl = "no-cache" 
    Response.AddHeader "Pragma", "No-Cache"
    %>
    <!--#include file="conn.asp"-->
    <%
    name=request.querystring("name")
    Set rs = Server.CreateObject ("ADODB.Recordset")
    sql = "Select * from u_ser where u_name='"&name&"'"
    rs.Open sql,conn,1,1
    if rs.eof and rs.bof then
     response.write("true")
    else
     response.write("false")
    end if
    rs.close
    set rs=nothing
    call CloseDatabase
    %>
      

  3.   

    http://blog.csdn.net/ws_hgo/archive/2009/07/28/4388800.aspx
      

  4.   

    JB9是javabulider9?这跟语言没关系,LZ研究一下AJAX的原理和实现就明白了。
      

  5.   

    到baidu, google去搜一下ajax学习就好了,建议用jquery,更加方便