根据选择的单选按钮,我在编辑复选框的禁用值和值属性时遇到问题。
当我选择输入#package-1然后输入#突出显示时,该功能有效。但是,当我再次选择输入#package 1时失败。当我这样做时,复选框上的值不会改变(这是不正确的)但禁用了属性(这是正确的)。
非常感谢任何帮助。
$(document).ready(function(){
$('.package-select').change(function(){
if ($('#package-2').is(':checked') || $('#package-1').is(':checked') ){
$('input#extrasRouter').removeAttr('disabled');
$('input#extrasRouter').val("36-Wireless router - £44.99 - TEST"); // Changing value to select the PAID FOR router
} else {
$('input#extrasRouter').val("21-Wireless router - FREE");
$('input#extrasRouter').attr('disabled', true);
}
});
});
<!-- Radio button that are being selected which should affect the below checkbox -->
<label for="package-3" class="package-select" id="tb-package-3">
<span class="name">Home Worker 20</span>
<input type="radio" value="16-Home Worker 20 - £35 per month" id="package-3" class="validate required" name="package">
</label>
<label for="highlighted" class="package-select" id="tb-highlighted">
<span class="name">Home 20</span>
<input type="radio" value="10-Home 20 - £22 per month" id="highlighted" class="validate required" name="package">
</label>
<label for="package-2" class="package-select" id="tb-package-2">
<span class="name">Home 10</span>
<input type="radio" value="12-Home 10 - £17 per month" id="package-2" class="validate required" name="package">
</label>
<label for="package-1" class="package-select" id="tb-package-1">
<span class="name">Basic</span>
<input type="radio" value="13-Basic - £10 per month" id="package-1" class="validate required" name="package" >
</label>
<!-- Checkbox that is being edited -->
<input type="checkbox" checked="" name="options[]" id="extrasRouter" value="21-Wireless router - £44.99" />
答案 0 :(得分:0)
checked
是属性,不是属性。改变这些:
$('input#extrasRouter').removeAttr('disabled');
...
$('input#extrasRouter').attr('disabled', true);
到这些:
$('input#extrasRouter').prop('disabled', false);
...
$('input#extrasRouter').prop('disabled', true);
尝试在重新启用之前设置值,而不是在禁用该框时设置值。