当单击单选按钮时,我有如下代码 是的,必须启用文本框,否则必须将其禁用。请有人帮助我。谢谢
<div class="label_left">
<label>Does the tourism office operate on a biennial budget? : (Y/N)</label>
</div>
<div class="text_right">
<br>
<br>
<input type="radio" id="high" name="high" />
<label>Y</label>
<input type="radio" id="high" name="high" />
<label>N</label>
<br />
<br />
<br />
</div>
<div class="label_left">
<label>If YES,please indicate when the current biennial budget began: (mm/dd/yy)</label>
</div>
<div class="text_right">
<br>
<br>
<input type="text" name="date_biennial_budget" id="date_biennial_budget" value="" size="30" />
<br />
<br />
<br />
</div>
最佳答案
首先确保您的 ID 是唯一的..
使用 prop()
来启用/禁用元素..(确保为单选按钮添加值...这是您的代码中缺少的) p>
HTML
<input type="radio" id="high" value="Y" name="high" />
<input type="radio" id="high" value="N" name="high" />
jquery
$('input[name="high"]').change(function(){
if($(this).val() == 'Y'){
$('#date_biennial_budget').prop('disabled',false);
}else{
$('#date_biennial_budget').prop('disabled',true);
}
});
关于jquery - 如何使用 jquery 启用文本区域或输入类型 ="text",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17874583/