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

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

Jun 13, 2016 pm 01:34 PM
document getelementbyid lt quot xhr

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

PHP code
<!--

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

-->
  
Copy after login
请输入名称


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;
        }
    }
}

Copy after login


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();
?>

Copy after login


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

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

document.getElementById("button").disabled    = 'true';//禁用
document.getElementById("button").removeAttribute("disabled");//恢复
<br><font color="#e78608">------解决方案--------------------</font><br>
Copy after login
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>
Copy after login
Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

GTA 6 document gives a detailed overview of all leaks GTA 6 document gives a detailed overview of all leaks Sep 08, 2024 am 06:37 AM

On September 3, version 1.5 of the Grand Theft Auto VI document which provides a detailed overview of everything that is known about the game to date. The updated version of the document was announced in a trailer published on X (formerly Twitter).??

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

How to solve the problem that document.cookie cannot be obtained How to solve the problem that document.cookie cannot be obtained Nov 23, 2023 am 10:02 AM

Solutions for document.cookie not being obtained: 1. Browser privacy settings; 2. Same-origin policy; 3. HTTPOnly Cookie; 4. JavaScript code error; 5. Cookie does not exist or expires; 6. Cross-domain issues; 7. Viewer mode; 8. Server problems; 9. JavaScript execution timing; 10. Check console log, etc.

How to use getElementById How to use getElementById Sep 01, 2023 am 11:03 AM

getElementById can obtain the corresponding HTML element through the id attribute of the element, and then operate and modify it conveniently. Whether it is to dynamically change the content and style of an element or add an event listener, getElementById is a very commonly used method.

Microsoft is rolling out Windows 11 23H2 build to the release preview channel with Copilot Microsoft is rolling out Windows 11 23H2 build to the release preview channel with Copilot Sep 28, 2023 pm 07:17 PM

Everyone is looking forward to today's Windows 1123H2 release. In fact, Microsoft has just launched updates to the release preview, which is the closest channel before the official release stage. Known as Build 22631, Microsoft said they are rolling out the new rebranded chat app, phone link, and play together widgets that have been tested on other internal channels over the past few months. "This new update will have the same servicing branch and codebase as Windows 11 version 22H2 and will be cumulative with all newly announced features, including Copilot in Windows (preview)," Microsoft promises. Redmond officials further

Introduction to document object in js Introduction to document object in js Feb 18, 2024 pm 01:06 PM

Introduction to the Document object in JavaScript and code examples: In JavaScript, the Document object is an interface that represents the entire HTML document. It provides access and operation methods to the HTML document. This article will introduce the common methods and properties of the Document object and provide some specific code examples. getElementById method getElementById is an important method of the Document object, used to

Document properties and methods of JS Document properties and methods of JS Mar 14, 2024 am 10:47 AM

Common document properties and methods: Properties: 1. document.title: Get or set the title of the document, usually displayed on the title bar or label of the browser; 2. document.URL: Get the complete URL of the document; 3. document. documentElement: Get the root element of the document, usually the <html> element; 4. document.body: Get the <body> element of the document; 5. document.head, etc.

How does a Java crawler implement Jsoup using the dom method to traverse the Document object? How does a Java crawler implement Jsoup using the dom method to traverse the Document object? May 14, 2023 pm 02:19 PM

First give the web page address: https://wall.alphacoders.com/featured.php?lang=Chinese Main steps: Use the connect method of Jsoup to obtain the Document object Stringhtml="https://wall.alphacoders.com/featured.php ?lang=Chinese";Documentdoc=Jsoup.connect(html).get();If the content is too long, it will not be displayed again. Let’s take this section as an example: AboutUsFAQPrivacyP

See all articles