启用禁用无线电选择的选择/下拉列表 [英] enable disable select / dropdown on radio selection
问题描述
我是JQuery的新手,请认为我是新手。我有一个PHP表单,我有一个单选按钮。根据选择的无线电,我想禁用选择/下拉列表。以下是场景:
I am very new to JQuery, please consider me as a novice. I have a PHP form where in I have a Radio button. Based on the which radio is selected I would like to disable the select / dropdown. Below is the scenario:
单选按钮:每日和其他
选择:Deity Name
Radio Button: Daily and Misc Select: Deity Name
如果用户选择Misc然后选择(Deity Name)应该被禁用,反之亦然。
If the user selects Misc then Select (Deity Name) should be disabled and vice versa.
我已经在我的页面上导入了JQuery。
I have already imported the JQuery on my page.
Header.php
!-- JQuery 1.12.3 JS -->
<script src="../js/jquery-1.12.3.min.js"></script>
HTML代码
<tr>
<td class="col-md-4"><label class="control-label">Pooja Type</label></td>
<td class="col-md-8" align="center">
<label class='radio-inline'><input type='radio' name='poojaType' value='daily' checked>Daily</label>
<label class='radio-inline'><input type='radio' name='poojaType' value='misc'>Misc</label>
</td>
</tr>
<tr>
<td class="col-md-4"><label class="control-label" for="deity">Deity Name</label></td>
<td class="col-md-8"><select class="form-control" name="deityName">
请建议。
推荐答案
按照以下代码:
假设您有两个单选按钮,如下所示:
Assume you have two radio buttons as below:
<input type='radio' name='radios' id='rdbDaily' value='Daily' /> Daily
<input type='radio' name='radios' id='rdbMisc' value='Misc' /> Misc
和一个下拉列表如下:
<select id='selectordropdown'>
<option>Deity Name</option>
</select>
您可以使用以下jquery通过选择单选按钮启用或禁用您的下拉列表:
you can use below jquery to enable or disable your dropdown by selecting radio buttons:
$('input:radio[name="radios"]').change(function() {
if ($(this).val()=='Daily') {
$('#selectordropdown').attr('disabled', false);
}
else if ($(this).val()=='Misc') {
$('#selectordropdown').attr('disabled', true);
}
});
或者您也可以使用以下jquery来启用/取消您的下拉菜单:
or you can also use below jquery to enable / disbale your dropdown:
$("#rdbDaily").click(function() {
$("#selectordropdown").attr("disabled", false);
});
$("#rdbMisc").click(function() {
$("#selectordropdown").attr("disabled", true);
});
这篇关于启用禁用无线电选择的选择/下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!