繁体   English   中英

基于单选按钮选择禁用复选框上的更改值属性的问题

[英]Issue with changing value attribute on disabled checkbox based on radio button selection

根据选择哪个单选按钮,在复选框上禁用和值属性的编辑时出现问题。

当我选择input#package-1,然后输入#highlighted时,该函数起作用。 但是,当我再次选择input#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 - &pound;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 - &pound;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 - &pound;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 - &pound;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 - &pound;44.99"   />

checked是一个属性,而不是一个属性。 更改这些:

$('input#extrasRouter').removeAttr('disabled');
...
$('input#extrasRouter').attr('disabled', true);

这些:

$('input#extrasRouter').prop('disabled', false);
...
$('input#extrasRouter').prop('disabled', true);

另外,请尝试在禁用之前/之后重新设置值,而不是在禁用此框时进行设置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM