[英]Reset a dropdown menu when hidden
I have a form that utilizes a drop-down menu that is toggled by radio buttons. 我有一个利用通过单选按钮切换的下拉菜单的表单。 However I'm trying to clear the menu selection if the menu is hidden.
但是,如果菜单隐藏,我将尝试清除菜单选择。 I'm using JavaScript to show/hide the drop-down but I can't seem to get the drop-down menu to clear when hidden.
我正在使用JavaScript显示/隐藏下拉菜单,但隐藏时似乎无法清除下拉菜单。
This is the JavaScript I have so far, any insights would be appreciated: 这是我到目前为止拥有的JavaScript,任何见解将不胜感激:
<script type="text/javascript">
if(document.readyState === "complete")
{
if (document.getElementById('yesCheck').checked) {
document.getElementById('DropDownList').style.visibility = 'visible';
}
}
function yesnoCheck() {
if (document.getElementById('yesCheck').checked) {
document.getElementById('DropDownList').style.visibility = 'visible';
}
else {
document.getElementById('DropDownList').style.visibility = 'hidden';
var elements = document.getElementById("DropDown").options;
for(var i = 0; i < elements.length; i++){
elements[i].selected = null;
}
}
}
Try this one 试试这个
document.getElementById("DropDownList").selectedIndex = "0";
http://www.w3schools.com/jsref/prop_select_selectedindex.asp http://www.w3schools.com/jsref/prop_select_selectedindex.asp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.