Javascript 禁用文本输入,除非选择了选择器选项

Javascript 禁用文本输入,除非选择了选择器选项,javascript,jquery,html,Javascript,Jquery,Html,我有一个带有选项列表的选择器。其中一个选项是“其他”,在这种情况下,用户可以在下面的文本框中输入自己的选项 如何使文本框禁用并变灰,直到在选择“其他”选项时才变为活动状态 <select id = "list" name="Optionlist"> <option value = "1">Option one</option> <option value = "2">Option two</option> <

我有一个带有选项列表的选择器。其中一个选项是“其他”,在这种情况下,用户可以在下面的文本框中输入自己的选项

如何使文本框禁用并变灰,直到在选择“其他”选项时才变为活动状态

<select id = "list" name="Optionlist">
    <option value = "1">Option one</option>
    <option value = "2">Option two</option>
    <option value = "3">Option three</option>
    <option value = "4">Other</option>
</select>
<br><br>
<label for="Other">Other: </label>
<input type="text" name="Other" id="otherbox"/>

选择一
选择二
选择三
其他


其他:
也许有点像这样:

$(文档).ready(函数(){
$(“#列表”).change(函数(){
$(“#otherbox”).prop(“disabled”,this.value!=“4”);
}).change();
});

选择一
选择二
选择三
其他


其他:
也许有点像这样:

$(文档).ready(函数(){
$(“#列表”).change(函数(){
$(“#otherbox”).prop(“disabled”,this.value!=“4”);
}).change();
});

选择一
选择二
选择三
其他


其他:
$('#list').change(function(){//on-change-of-select
$('#otherbox').prop('disabled',$('option:selected',this).val()!='4');//检查值是否不是其他值,然后禁用
}).change()//手动调用更改,以便加载时运行更改事件

选择一
选择二
选择三
其他


其他:
$('#list').change(function(){//on-change-of-select
$('#otherbox').prop('disabled',$('option:selected',this).val()!='4');//检查值是否不是其他值,然后禁用
}).change()//手动调用更改,以便加载时运行更改事件

选择一
选择二
选择三
其他


其他:

选择一
选择二
选择三
其他


其他: 函数func(obj){ document.getElementById('otherbox').setAttribute('disabled',true); 如果(对象值==4) document.getElementById('otherbox')。removeAttribute('disabled'); }

选择一
选择二
选择三
其他


其他: 函数func(obj){ document.getElementById('otherbox').setAttribute('disabled',true); 如果(对象值==4) document.getElementById('otherbox')。removeAttribute('disabled'); }
完美。谢谢你。当时间限制结束时,将选择作为最佳答案。什么是
$('option:selected',this).val()
做那件事
这个。值
不完美。谢谢你。当时间限制结束时,将选择作为最佳答案。什么是
$('option:selected',this).val()
这样做
这个.value
不这样做?