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

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

WBOY
WBOYOriginal
2016-06-13 10:17:191041browse

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

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 Documentvar 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>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn