我是JQuery的新手,请认为我是新手。我有一个PHP表单,我有一个单选按钮。根据选择的无线电,我想禁用选择/下拉列表。以下是场景:
单选按钮:每日和其他 选择:Deity Name
如果用户选择其他,则应禁用选择(Deity Name),反之亦然。
我已经在我的页面上导入了JQuery。
的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">
请建议。
答案 0 :(得分:4)
按照代码:
假设您有两个单选按钮,如下所示:
sudo service couchdb start
和下面的一个下拉列表:
<input type='radio' name='radios' id='rdbDaily' value='Daily' /> Daily
<input type='radio' name='radios' id='rdbMisc' value='Misc' /> Misc
您可以使用以下jquery通过选择单选按钮来启用或禁用您的下拉列表:
<select id='selectordropdown'>
<option>Deity Name</option>
</select>
或者你也可以使用下面的jquery来启用/取消你的下拉列表:
$('input:radio[name="radios"]').change(function() {
if ($(this).val()=='Daily') {
$('#selectordropdown').attr('disabled', false);
}
else if ($(this).val()=='Misc') {
$('#selectordropdown').attr('disabled', true);
}
});
答案 1 :(得分:2)
您可以groovy.lang.MissingMethodException: No signature of method: grails.orm.HibernateCriteriaBuilder.lookup() is applicable for argument types: (com.my.package.MySystemService$_getByParams_closure1$_closure2$_closure3) values: [com.my.package.MySystemService$_getByParams_closure1$_closure2$_closure3@59b6da8b]
checked value
change event
获取radio button
并将其设置为属性disabled
,如下所示
$('input[name="poojaType"]').on('change', function() {
$('select[name="deityName"]').attr('disabled', this.value != "daily")
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<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>
<select name="deityName">
<option>Value 1</option>
<option>Value 2</option>
<option>Value 3</option>
<option>Value 4</option>
</select>
</td>
</tr>
答案 2 :(得分:0)
以下是JQuery的代码:
<script>
$(':radio[name=poojaType]').change(function () {
var prop = this.value == 'misc';
$('select[name=deityName]').prop({ disabled: prop, required: !prop });
});
</script>