在DropDownList中onChange和onSelect [英] onChange and onSelect in DropDownList
问题描述
我有一个DropDownList,询问用户他是否想加入俱乐部:
您是否想加入俱乐部
是
不是
在此列表中还有另一个列表,它被设置为作为默认值禁用。这个名单有俱乐部的部门。这个列表在用户选择Yes之前不会被启用。
我构建了下面的代码,但是我无法解决的问题是让我们假设用户选择Yes,然后他改变他的决定,所以他会再次选择No。在这种情况下,部门列表仍然可用。我希望在他再次选择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 =mySelectonChange =enable();>
< option onSelect =disable();>否< / option>
< option onSelect =enable();>是< / option>
< / select>
< select id =mySelect1disabled =disabled>
< option> Dep1< / option>
< option> Dep2< / option>
< option> Dep3< / option>
< option> Dep4< / option>
< / select>
< / form>
< / body>
< / html>
我认为 谢谢 我会这样做 jsFiddle示例 。 JavaScript: HTML: I have a DropDownList that asks the user if he want to join the club: Under this list there is another list that is set to disabled as a default. This list has the departments of the club. This list will not be enabled until the user chooses Yes. I built the following code but the problem that I couldn't solve is let's assume the user chooses Yes then he changes his decision so he will choose No again. In this case the list of the departments still enabled. I want it to be disabled when he chooses No again. I thought that Thanks I'd do it like this jsFiddle example. JavaScript: HTML:
这篇关于在DropDownList中onChange和onSelect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! onSelect =disable();$ c
function check(elem){
document.getElementById('mySelect1')。disabled =!elem.selectedIndex;
}
<形式>
< select id =mySelectonChange =check(this);>
< option>无< / option>
< option>是< / option>
< / select>
< option> Dep1< / option>
< option> Dep2< / option>
< option> Dep3< / option>
< option> Dep4< / option>
< / select>
< / form>
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();"
would solve the problem but it still doesn't work.function check(elem) {
document.getElementById('mySelect1').disabled = !elem.selectedIndex;
}
<form>
<select id="mySelect" onChange="check(this);">
<option>No</option>
<option>Yes</option>
</select>
<select id="mySelect1" disabled="disabled" >
<option>Dep1</option>
<option>Dep2</option>
<option>Dep3</option>
<option>Dep4</option>
</select>
</form>