我有一个表格,其中包含要发送到 CC 处理的金额的多个选项。我希望用户选择付款类型,然后激活金额输入字段。我试图通过将单选按钮的 id 设置为对应于金额输入字段来做到这一点。如何根据选择的单选按钮启用输入金额字段?
HTML
<input name="doantion-type" id="general" type="radio" value="General" />
<input name="doantion-type" id="occasion" type="radio" value="Occasion" />
<input name="doantion-type" id="building" type="radio" value="Building" />
<input name="doantion-type" id="program" type="radio" value="Program" />
<input id="general" autocomplete="off" class="input required" type="text" size="30" name="Amount">
<input id="occasion" autocomplete="off" class="input required" type="text" size="30" name="Amount">
<input id="building" type="hidden" value="1000" name="Amount">
<input id="program" type="hidden" value="180" name="Amount">
jQuery
$("input[name=Amount]").prop('disabled', true);
$('input[name=doantion-type]:radio').click(function() {
var selectedDonation = '#' + $(this).attr('id');
//alert(selectedDonation);
$(selectedDonation).prop('disabled', false);
});