请教大师们,查询注册用户名已存在时按钮不提交,不跳转,怎么实现?
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->
<!--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; } }}
<!--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();?>
document.getElementById("button").disabled = 'true';//禁用document.getElementById("button").removeAttribute("disabled");//恢复<br><font color="#e78608">------解决方案--------------------</font><br>
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>