【发布时间】:2012-03-29 23:37:03
【问题描述】:
我有一个 DropDownList 询问用户是否想加入俱乐部:
Do you want to join the club
Yes
No
在此列表下还有另一个默认设置为禁用的列表。此列表包含俱乐部的部门。在用户选择“是”之前,不会启用此列表。
我构建了以下代码,但我无法解决的问题是假设用户选择是,然后他改变了他的决定,因此他将再次选择否。在这种情况下,部门列表仍然启用。我希望在他再次选择否时禁用它。
<html>
<head>
<script type="text/javascript">
function disable()
{
document.getElementById("mySelect1").disabled=true;
}
function enable()
{
document.getElementById("mySelect1").disabled=false;
}
</script>
</head>
<body>
<form>
<select id="mySelect" onChange="enable();">
<option onSelect="disable();">No</option>
<option onSelect="enable();">Yes</option>
</select>
<select id="mySelect1" disabled="disabled" >
<option>Dep1</option>
<option>Dep2</option>
<option>Dep3</option>
<option>Dep4</option>
</select>
</form>
</body>
</html>
我以为onSelect="disable();" 可以解决问题,但还是不行。
谢谢
【问题讨论】:
-
看起来单选按钮会更合适。此外,
onselect不是 select 和 option 元素的有效属性。
标签: javascript html onchange