以下的代码 必须在点击value="检测标题是否已存在" 后才能知道 标题是否已存在
如何实现标题输入进去了就自动的检测呢?就如:我们到某网站去注册的时候,
在你输入用户名的时候,就自动的检测出:此用户名已经存在 或 此用户名可以注册。有请高手来指教啊  感激不尽啊<td>
<input type="text" name="info[title]" id="title" value="" size="50" class="inputtitle"  onBlur="$.post('api/get_keywords.php?number=3&sid='+Math.random()*5, {data:$('#title').val()}, function(data){if(data) $('#keywords').val(data); })"/> <input type="button" value="检测标题是否已存在" onClick="$.post('?mod=phpcms&file=content&catid=12', { action : 'check_title', c_title:$('#title').val()}, function(data){ $('#t_msg').html(data); })">
&nbsp;<span style="color:'#ff0000'" id='t_msg'></span>
</td>

解决方案 »

  1.   

    把检测标题是否存在的js事件放到前面失去焦点onBlur=""里面,,,这样onBlur有2个js语句,注意之间加上一个;
      

  2.   

    在onblur事件中添加方法
    <td>
    <input type="text" name="info[title]" id="title" value="" size="50" class="inputtitle"  onBlur="check()"/> 
    </td><script>
    function check(){
    第一步:检验是否存在,返回能标识是否存在的值
    第二步:如果存在,提示标题已存在,如alert(“标题已存在”)
    }
    </script>
      

  3.   

    用AJAX 可以实现不过有点麻烦 用jquery就容易多了 你的结贴率就0 所以告诉你用Ajax怎么实现吧
    //====JS文件=======
    //实例化XMLHttpRequest对象
    var ajax = false;
    if(window.XMLHttpRequest)
    {
    ajax=new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
      try{ 
          ajax=new ActiveXObject("Microsoft.XMLHTTP");
         }catch(e1)
         {
           try{
                ajax=new ActiveXObject("Msxml2.XMLHTTP");
               }catch(e2){}
         }
    }
    if(!ajax)
    {
    alert("some...");
    }//检查是否为空 并给出提示
    function check_username(username){
    if(document.myform.username.value==""){
       document.getElementById('chkuser').innerHTML=" <font color=red>用户名不能为空</font>";
            document.myform.username.focus();
            return false;
       }// 检查用户名是否已经被注册过   
    if(ajax){
    ajax.open("GET","reg.php?username="+username,true);
    ajax.onreadystatechange=handle_check;
    ajax.send(null);
    }else{
    document.getElementById('chkuser').innerHTML='ajax is error!';

    }
    function handle_check(){
    if(ajax.readyState==4)
                {
                    if(ajax.status==200)
                    {
                     document.getElementById('chkuser').innerHTML=ajax.responseText;  
                    }
                } 
    }
    //=======HTML===============
    <td><input name="username" type="text" id="username" size="20"  onblur="check_username(this.form.username.value)"/>
          &nbsp;<span id="chkuser"><font color=red>请输入用户名</font></span></td>
    //=====PHP文件-reg.php==================
    if(isset($_GET['username'])&&$_GET['username']!=""){   
    $username=trim($_GET['username']);
    $sql="select * from `user_table` where `username`='".$username."'"; 
    $query=mysql_query($sql);  //好久没写 可能SQL函数有错误 我想这里你应该明白
    $info=mysql_fetch_array($query);
    if(is_array($info)){ 
    echo "<font color='red'>It is reged</font>"; 
    }else{ 
    echo "<font color='red'>It is ab</font>"; } 
    }
    //基本功能就完成了  别的自己无完善!
      

  4.   

    onblur失去焦点。调用自定义的检查函数就可以的了