0

私のページのHTMLは次のとおりです。

     <!DOCTYPE html>

        <html>

    <body>

    <link href = "sites.css" type = "text/css" rel = "stylesheet"/>

    <image src = "beach_houses.jpg" id = "sites">

    <form id = "details">
     Please enter your name: <input type = "text" id = "name"><br/><br/>
     Please provide a valid e-mail: <input type = "text" id = "e-mail"><br/><br/>
     I am on a tour<input type = "checkbox" id = "status">

    <div id = "further"><br/>
     Indicate your gender 
     M<input type = "radio" name = "gender"value = "male" id = "M"> 
     F<input type = "radio" name = "gender" value = "female" id = "F">
  </div><br/></br>
    <input type = "submit" value = "submit!">
</form>

    <br/><br/><div id = "error" ></div>

    </body>

    <script src = "function.js" type = "text/javascript"></script>

    </html>

そして、ここにjavascriptがあります:

Images.onclick = function() {


clearInterval(iHandle);
}


function prepare() {

document.getElementById("status").onclick = function() {

    if (document.getElementById("status").checked) 

        document.getElementById("further").style.display = "block";
    else 

        document.getElementById("further").style.display = "none";

    document.getElementById("further").style.display = "none";

};


document.getElementById("details").onsubmit = function() {

    if(document.getElementById("name").value == "") {

        document.getElementById("error").innerHTML = "Please provide a name!";

        document.getElementById("error").style.color = "red";

        return false;

    }

    else if (document.getElementById("e-mail").value == "") {

        document.getElementById("error").innerHTML = "Please provide a valid e-mail address!";

        document.getElementById("error").style.color = "red";

        return false;

    }
};



}



window.onload = function() {

    prepare();
};

アイデアは、ツアー中のチェックボックスをオンにすると、性別を示す質問がポップアップするというものです。ただし、逆のことが起こります。その質問はデフォルトで表示されているようで、チェックボックスをクリックすると表示されなくなります。どうしてこれなの?

よろしくお願いします

4

1 に答える 1

1

<div id = "further">をに変更<div id = "further" style="display:none">

document.getElementById("status").onclick = function() {

    if (document.getElementById("status").checked) {

        document.getElementById("further").style.display = "block";
    }
    else {
        document.getElementById("further").style.display = "none";
    }
};
于 2013-01-09T11:51:58.553 に答える