【js】遍历指定input

            success: function (data) {
                        if (data == null) {
                            $("input[name='menu']").attr("checked", false);
                        }
                        else {
                            role_id = JSON.stringify(data.role_id);
                            $("input[name='menu']").each(function () {
                                if ($(this).val() == role_id) {
//                                    $(this).attr("checked", true);
                                    $(this).prop('checked', true);
                                } else {
//                                    $(this).attr("checked", false);
                                    $(this).prop('checked', false);
                                }
                                console.log(role_id + "..." + $(this).val() + "..." + $(this).prop('checked'));
                            });
                        }
                    },
1.遍历指定input。
  $("input[name='menu']").each(function () {

  }

2.用prop,不用attr

$(this).attr("checked", true);

$(this).prop('checked', true);


原文地址:https://www.cnblogs.com/CESC4/p/7643957.html