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

这个想法是,当我在旅行复选框被选中时,指示您的性别问题会弹出。然而,情况恰恰相反;默认情况下,该问题似乎是可见的,当我单击复选框时它变得不可见。为什么是这样?

提前谢谢你saad

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 回答