我有一个下拉框,一旦选中显示特定的表单元素,这是完美的,但只要我添加div类到元素(下拉框)css类仍然显示即使该特定元素不是地选择。
是否可以将css类与表单元素一起隐藏,下面是我的代码。
的Javascript
function check() {
var dropdown = document.getElementById("filtercriteria");
var current_value = dropdown.options[dropdown.selectedIndex].value;
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";
}
HTML下拉选择框
<select id="filtercriteria" onChange="check(this);" >
<option value="select">Select</option>
<option value="page_name">Page Name</option>
<option value="postcode">Postcode</option>
<option value="country">Country</option>
<option value="search_term">Search Term</option>
<option value="referrer">Refferer</option>
<option value="country">Country</option>
<option value="search_term">Search Term</option>
<option value="referrer">Referrer</option>
<option value="page_visits">Page Visits</option>
<option value="repeater">Repeater</option>
<option value="owner">Owner</option>
<option value="visitor_type">Visitor Type</option>
</select>
带有Div类的第一个隐藏元素,即使未选择此选项也会显示。
<div id="pagename">
<div class="select-div">
<select id="contains" name="contains" display="none" class="hideme">
<option value="contains">contains</option>
<option value="exact">exact</option>
</select>
</div>
<input name="term" id="term" type="text" class="hideme" display='none' />
</div>
任何建议都将不胜感激。