当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - HIde form elements when page initially loads

问题描述:

HI I have a drop down menu, which determins which sections of a form should be displayed. This works, except for when the initial page loads all of the elements are shown. Once you make a selection it then displays only the correct elements.

Below is my Javascript, is there a way to set all of the elements to hidden initially, sorry if this is a stupid question but i am new to javascript.

if (current_value == "page_name") {

document.getElementById("contains").style.display = "block";

document.getElementById("term").style.display = "block";

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

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

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

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

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

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

}

else if (current_value == "postcode") {

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

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

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

document.getElementById("postcodes").style.display = "block";

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

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

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

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

}

网友答案:

Give class attribute to all element.

Eg: if you have a input element like

<input type="text" name="something" id="something" class="hideme" /> 

hide element by using same class name for all elements as I explained above

$(document).ready(function() {
    $(".hideme").hide();
});
分享给朋友:
您可能感兴趣的文章:
随机阅读: