[英]HTML Javascript, checkbox toggles label and dropdown list visibility
I'm halfway to getting this correct, but i am currently stuck. 我已经半途而废了,但我目前陷入困境。 Firstly i would like the label and dropdown to be hidden be default.
首先,我希望默认隐藏标签和下拉菜单。 This i have achieved using css:
我已经使用CSS实现了这一点:
#unis
{
visibility:hidden;
}
The bit i am slightly stuck on is how to group the items, i have used: 我稍有停留的一点是如何使用我对这些项目进行分组:
<div class='row'>
<div id = "unis">
<label id='Universitylbl' for='University'>University institution:</label>
<select name="uni">
<option value="uni1">uni1</option>
<option value="uni2">uni2</option>
<option value="uni3">uni3</option>
<option value="uni4">uni4</option>
<option value="uni5">uni5</option>
</select><br />
</div>
</div>
and the javascript to toggle the visibility: 和JavaScript来切换可见性:
function toggle(elementID){
var target1 = document.getElementById(elementID)
if (target1.style.display == 'none') {
target1.style.display = 'block'
}
else
{
target1.style.display = 'none'
}
}
but the above code doesn't appear to work? 但是上面的代码似乎不起作用?
It seems you are assigning target2
a value and altering the display of target1
. 似乎您正在为
target2
分配一个值并更改target1
的显示。 Shouldn't that be the same object ? 那不是同一对象吗? (
target
, for example ?) (例如
target
?)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.