Select 所有组中没有选中复选框的特定单选按钮

Select specific radio buttons in all groups with no selected checkboxes

我需要:

  1. 获取所有没有选项的无线电组 selected
  2. 从这些组中获得输入 "data-correctanswer"

有没有比我现有的更好的方法? (正在运行)

jsfiddle

(只需要select A和H)

HTML:

<form class="multiForm trueFalse">
    <ul>
        <li>
            <input data-correctanswer="correct" name="question1" type="radio"><span>A</span>

        </li>
        <li>
            <input name="question1" type="radio"><span>B</span>

        </li>
    </ul>
    <ul>
        <li>
            <input name="question2" type="radio" checked="checked"><span>C</span>

        </li>
        <li>
            <input data-correctanswer="correct" name="question2" type="radio"><span>D</span>

        </li>
    </ul>
    <ul>
        <li>
            <input name="question3" type="radio"><span>E</span>

        </li>
        <li>
            <input data-correctanswer="correct" name="question3" type="radio" checked="checked"><span>F</span>

        </li>
    </ul>
    <ul>
        <li>
            <input name="question4" type="radio"><span>G</span>

        </li>
        <li>
            <input data-correctanswer="correct" name="question4" type="radio"><span>H</span>

        </li>
    </ul>
</form>

JS:

$(document).ready(function () {

    var radio_buttons = $('.multiForm input[name*="question"]').not(':checked');
    var arr = [];
    $('.multiForm ul').each(function () {
        notSelectedRadioGroup = $(this).find('input[name*="question"]');
        if (notSelectedRadioGroup.filter(':checked').length == 0) {
            arr.push($(this));
        }
    });

    $(arr).each(function () {
        $(this).find('input:radio[data-correctanswer]').not(':checked').addClass('selected');
    });
});

试试,

    $(document).ready(function () {
      var arr = [];
      $('.multiForm ul').each(function () {
        var x = $(":radio", this);
        var cond = x.filter(":not(:checked)").length === x.length;
        if(cond)
         arr.push(x.filter("[data-correctanswer]").data("correctanswer"));         
      });
      alert(JSON.stringify(arr));
    });

DEMO

$(document).ready(function () {
    $('.multiForm ul').each(function () {
        var x = $(":radio", this);
        var cond = x.filter(":not(:checked)").length === x.length;
        if (cond)
          x.filter("[data-correctanswer]").closest("li").css("color","red");
    });     
});

DEMO II