jquery 插件文档已经很全了,还有demo.自己要学会钻研啊.
记得不错的话.demo中有个ajax列子.

解决方案 »

  1.   

    JS:
    $("#username").blur(function() {
    var validateUsername = $('#validateUsername');
    var t = this; 
            if (this.value != this.lastValue) {        
             if (this.timer) clearTimeout(this.timer);
                validateUsername.html('用户名检测中...');
                this.timer = setTimeout(function () {
                    $.ajax({
    type: "POST",
    url: "reg.php?action=checkusername",
    data: 'username=' + t.value,
    success: function(msg){
    if(msg==1) validateUsername.html('该用户名已存在');
    else validateUsername.html('该用户名可用');
    }
                    });
                }, 200);
                this.lastValue = this.value;
            }
    });HTML:
    <tr class="dark-row"> 
            <td width="85" class="require-field">帐户名称</td>
            <td width="227"><input name="username" type="text" class="text-box" id="username" size="20"/><span id="validateUsername"></span></td>
          </tr>PHP:
    reg.php
    名字检查
    $username = $_POST['username'];相关数据库操作 if (名字存在) {
    echo 1;
    }else 
    echo 0;
    exit;
        }
    }
      

  2.   

    我只有一个jquery.js,别的都没有啊,没看到demo,方便给我传一个么?谢啦
      

  3.   

    十分感谢,但是我在reg.php 中的连接数据库检测用户名时,如果只是简单的
    echo json_encode(array ('username'=>$_REQUEST['username']));的话没问题,但是这个文件已连接数据库就出错,没有反应,这个文件应该怎么写啊?谢啦!!!
      

  4.   

    http://docs.jquery.com/Plugins/Validation
    自己去看下吧.
      

  5.   

    呵呵,例子不多,没看到我想要的,我想要看看就像2楼哪样,前台数据传到.php文件时连接数据库做验证时的代码,能给我发过来些例子么?十分感谢!!!
      

  6.   

    方便给我个完整的reg.php代码么?十分感谢~
      

  7.   

    都是最简单的数据库操作不用再给你贴代码了吧?链接数据库出错,那就应该检查你的链接数据库部分是否正确。$dbh =  mysql_connect('localhost:3306','帐户','密码'); 
    mysql_select_db('数据库名称');
    $sql = "select username from 表名 where username='$username'";
    $ret = mysql_query($sql);
    $row = mysql_fetch_array($ret); 
    if($row['username'])
      echo 1;
    else
      echo 0;
      

  8.   

    哦,谢谢,原来我昨天sql语句写错了,忘了个',所以一直没有结果,十分感谢~
      

  9.   

    三个页面conn.php GET.php action.php(conn.php POST.php action.php) dreamweaver编译器
    -----------------conn.php-----------
    <?php$link=mysql_connect("localhost","root","315824")
    or die("错误信息:".mysql_error());$db=mysql_select_db("ambow");
    mysql_query("set names gb2312");?>
    ----------GET.php------------------<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>AJAX</title>
    </head>
    <script type="text/javascript">
    var xmlHttp;function createXMLHttpRequest(){    if(window.ActiveXObject){
        xmlHttp=new ActiveXObject("Microsoft.XMLHttp");
    }else if(window.XMLHttpRequest){
        xmlHttp=new XMLHttpRequest();
    }
    }function GetRequest(txtVal){    createXMLHttpRequest();
    xmlHttp.onreadystatechange=Get;
    xmlHttp.open("GET","action.php?txt="+txtVal,true);
        xmlHttp.send(null);
    }function  Get(){    if(xmlHttp.readyState==4){
         if(xmlHttp.status==200){
      document.getElementById("msg").innerHTML=xmlHttp.responseText;   
     }
    }}</script><body>
    用户名:<input type="text" name="txt" onBlur="GetRequest(this.value)" /> 
            <span id="msg"></span>
    </body>
    </html>
    ----------action.php----------------<?php
    require_once("conn.php");header("Content-type: text/html; charset=gb2312");
    $name=$_REQUEST["txt"];

    $sql="select * from student where sname='{$name}' ";
    $result=mysql_query($sql);
    $row=mysql_fetch_assoc($result);
    //echo $row["sname"];if($name == NULL){
        echo "用户名不能为空";
    }else if($row["sname"]!=NULL){
         echo "该用户名以存在!";
    }else{
         echo "用户名可用";
    }

    ?>------------POST.php---------------<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>AJAX</title>
    </head>
    <script type="text/javascript">
    var xmlHttp;function createXMLHttpRequest(){    if(window.ActiveXObject){
        xmlHttp=new ActiveXObject("Microsoft.XMLHttp");
    }else if(window.XMLHttpRequest){
        xmlHttp=new XMLHttpRequest();
    }
    }function PostRequest(txtVal){    createXMLHttpRequest();
    xmlHttp.open("POST","action.php",true);
    xmlHttp.onreadystatechange=Post;
    xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=gb2312");
        xmlHttp.send("txt="+txtVal);
    }function  Post(){    if(xmlHttp.readyState==4){
         if(xmlHttp.status==200){
      document.getElementById("msg").innerHTML=xmlHttp.responseText;   
     }
    }}</script><body>
    用户名:<input type="text" name="txt" onBlur="PostRequest(this.value)" /> 
            <span id="msg"></span>
    </body>
    </html>