简体   繁体   English

innerHTML不影响div

[英]innerHTML not affecting div

I have a problem with innerHTML I'm trying to replace all child elements of a div (wipe it out) and replace with a text. 我的innerHTML出现问题,我试图替换div的所有子元素(将其清除)并替换为文本。 Just to give you idea, this is a registration form, after clicking submit, it should clear the form and output some text. 只是为了给您一个想法,这是一个注册表单,单击提交后,它应该清除表单并输出一些文本。 It looks like it doesn't take any affect on the div that I am targeting 看来它对我定位的div没有任何影响

here is the function 这是功能

function signup() {
    var u = _("username").value;
    var e = _("email").value;
    var p1 = _("pass1").value;
    var p2 = _("pass2").value;
    var c = _("country").value;
    var g = _("gender").value;
    var status = _("status");
    if (u == "" || e == "" || p1 == "" || p2 == "" || c == "" || g == "") {
        status.innerHTML = "Fill out all of the form data";
    } else if (p1 != p2) {
        status.innerHTML = "Your password fields do not match";
    } else if (_("terms").style.display == "none") {
        status.innerHTML = "Please view the terms of use";
    } else {
        _("signupbtn").style.display = "none";
        status.innerHTML = 'please wait ...';
        var ajax = ajaxObj("POST", "signup.php");
        ajax.onreadystatechange = function() {
            if (ajaxReturn(ajax) == true) {
                if (ajax.responseText.trim() != "signup_success") {
                    status.innerHTML = ajax.responseText;
                    _("signupbtn").style.display = "block";
                } else {
                    _("signupform").innerHTML = "OK " + u + ", check your email inbox and junk mail box at <u>" + e + "</u> in a moment to complete the sign up process by activating your account. You will not be able to do anything on the site until you successfully activate your account.";
                }
            }
        }
        ajax.send("u=" + u + "&e=" + e + "&p=" + p1 + "&c=" + c + "&g=" + g);
}

and here is the form: 形式如下:

<form name="signupform" id="signupform" onsubmit="return false;">
    <div>Username: </div>
    <input id="username" type="text" onblur="checkusername()" onkeyup="restrict('username')" maxlength="16">
    <span id="unamestatus"></span>
    <div>Email Address:</div>
    <input id="email" type="text" onfocus="emptyElement('status')" onkeyup="restrict('email')" maxlength="88">
    <div>Create Password:</div>
    <input id="pass1" type="password" onfocus="emptyElement('status')" maxlength="16">
    <div>Confirm Password:</div>
    <input id="pass2" type="password" onfocus="emptyElement('status')" maxlength="16">
    <div>Gender:</div>
    <select id="gender" onfocus="emptyElement('status')">
        <option value=""></option>
        <option value="m">Male</option>
        <option value="f">Female</option>
    </select>
    <div>Country:</div>
    <select id="country" onfocus="emptyElement('status')">
        <?php include_once( "php_includes/template_country_list.php"); ?>
    </select>
    <div>
        <br>
        <br>
        <a href="#" onclick="return false" onmousedown="openTerms()">
        View the Terms Of Use
      </a>
    </div>
    <div id="terms" style="display:none;">
        <br>
        <br>
        <h3>Please read the Terms and Conditions (opens a new window)</h3>
        <a href="iLOVEiTtermsandCONS.pdf" title="Terms and Conditions" target="_blank">
            <p>Terms and Conditions</p>
        </a>
    </div>
    <br />
    <br />
    <button id="signupbtn" onclick="signup()">Create Account</button>
    <span id="status"></span>
</form>

any ideas what could be wrong? 有什么想法可能是错的吗? I'm not good with java script at all Thanks in advance. 我对Java脚本一点都不满意,谢谢。

I don't know what does _(" ").value mean. 我不知道_(" ").value是什么意思。 But if you change this style to document.getElementByid(" ") , it works. 但是,如果将此样式更改为document.getElementByid(" ") ,则可以使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM