Jqueyr determines the check of sample code for the checkbox group

  • 2020-03-26 23:50:08
  • OfStack

HTML:

  <tr>
                        <td align="right">
                        </td>
                        <td align="left" colspan="3">
                            <input type="checkbox" class="checkboxListItem" name="checkItem" value="3" id="slsa_approval" /> approval    
                            <input type="checkbox" class="checkboxListItem" name="checkItem" value="4" id="slsa_noApproval" /> Don't approve 
                        </td>
                    </tr>

Jquery:

$(function () {
    $(".checkboxListItem").change(    // Teachers' 
        function () {
            var $checkValue = $("input[name='checkItem']:checked").val();
            if ($checkValue == 3) {
                $("#slsa_approval").attr("checked", true);
                $("#slsa_noApproval").attr("checked", false); 
            }
            else {
                $("#slsa_approval").attr("checked", false);
                $("#slsa_noApproval").attr("checked", true); 
            }
        }); 
});

Judging by the value:

 var checkCheckbox = $("#slsa_approval").attr("checked");
        if (checkCheckbox == true) {
            auditState = "3";
        } else {
            auditState = "4";
        }

Related articles: