【发布时间】:2016-01-09 02:58:16
【问题描述】:
我有一个表单,其中有几个单选按钮和一个下拉框。
我想要什么?
- 当我选择单选按钮“收据”或“付款”时,下拉框必须处于活动状态。
- 当我选择单选按钮“其他收入”或“其他费用”时,必须禁用下拉框。
下面提到了我尝试过的 HTML 和 JS。任何帮助将不胜感激。
HTML
<label class="radio-inline"><input type="radio" name="type" id="type" value="receipt" onClick="party_check()" />Receipt</label>
<label class="radio-inline"><input type="radio" name="type" id="type" value="payment" onClick="party_check()" />Payment</label>
<label class="radio-inline"><input type="radio" name="type" id="type" value="other income" onClick="party_check()" />Other Income</label>
<label class="radio-inline"><input type="radio" name="type" id="type" value="other expense" onClick="party_check()" />Other Expense</label>
<select name="party" id="party" class="form-control">
<option value="">Please select an option</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
JS
function party_check(){
if((document.type[0].checked) || (document.type[1].checked)){
document.getElementById("party").disabled=false;
}
else
{
document.getElementById("party").disabled=true;
}
}
【问题讨论】:
标签: javascript html forms radio-button html-select