首頁 >後端開發 >php教程 > 请问大师们,查询注册用户名已存在时按钮不提交,不跳转,如何实现

请问大师们,查询注册用户名已存在时按钮不提交,不跳转,如何实现

WBOY
WBOY原創
2016-06-13 13:34:51888瀏覽

请教大师们,查询注册用户名已存在时按钮不提交,不跳转,怎么实现?

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
  
请输入名称


JScript code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
// JavaScript Document
var XHR;
function createXHR(){
    if(window.ActiveXObject){
        XHR=new ActiveXObject('Microsoft.XMLHTTP');
    }else if(window.XMLHttpRequest){
        XHR=new XMLHttpRequest();
    }
}
function checkname(){
    var username=document.form1.host.value;
    createXHR();    
    XHR.open("GET","./checkname.php?id="+username,true);
    XHR.onreadystatechange=byhongfei;
    XHR.send(null);
}
function byhongfei(){
    if(XHR.readyState == 4){
        if(XHR.status == 200){    
            var textHTML=XHR.responseText;            
            document.getElementById('msg').innerHTML=textHTML;
        }
    }
}



PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<?php mysql_connect("localhost",'root','123456');
    mysql_select_db('dodiscuz_freebb');
    $sql="select * from member where username='$_GET[id]'";
    $query=mysql_query($sql);
    if(is_array(mysql_fetch_array($query))){
        echo "用户名已存在";
    }else{
        echo "<font color=green>用户名可以使用";
    }
mysql_close();
?>



用户名存在时 注册 按钮怎样实现不可用状态 现在就是用户名存在也跳转到index.php?reg

------解决方案--------------------
JScript code

document.getElementById("button").disabled    = 'true';//禁用
document.getElementById("button").removeAttribute("disabled");//恢复
<br><font color="#e78608">------解决方案--------------------</font><br>
JScript code

function byhongfei(){
    if(XHR.readyState == 4){
        if(XHR.status == 200){    
            var textHTML=XHR.responseText;            
            document.getElementById('msg').innerHTML=textHTML;
            if(textHTML == "用户名已存在"){
              document.getElementById("button").disabled    = 'true';//禁用
            }
        }
    }
} <div class="clear">
                 
              
              
        
            </div>
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn