jqueyr判断checkbox组的选中(示例代码)

2020-05-17 06:23:32易采站长站整理

html:

  <tr>
                        <td align=”right”>
                        </td>
                        <td align=”left” colspan=”3″>
                            <input type=”checkbox” class=”checkboxListItem” name=”checkItem” value=”3″ id=”slsa_approval” />批准   
                            <input type=”checkbox” class=”checkboxListItem” name=”checkItem” value=”4″ id=”slsa_noApproval” />不批准
                        </td>
                    </tr>

jquery :

$(function () {
    $(“.checkboxListItem”).change(    //教师
        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);
            }
        });
});

通过值的判断:

 var checkCheckbox = $(“#slsa_approval”).attr(“checked”);