Javascript: 通过名称获取 iCheck radio 值

Javascript: get iCheck radio value by name

如何通过名称获取 iCheck radio 值,例如 $("input[type=radio][name=test]").val()?似乎它不工作。请参阅 JSFiddle

HTML

<div class="i-checks"><label> <input type="radio" checked="" value="a" name="test"> a </label></div>
<div class="i-checks"><label> <input type="radio" value="b" name="test"> b </label></div>
<div class="i-checks"><label> <input type="radio" value="c" name="test"> c </label></div>


The <span id='outputbythis' style='color:green'></span> is checked by $(this).val()
<br>
The <span id='outputbyname' style='color:red'></span> is checked by $("input[type=radio][name=test]").val()

JS

jQuery(document).ready(function ($) {

    $('input').iCheck({
        checkboxClass: 'icheckbox_flat-green',
        radioClass: 'iradio_flat-green'
    });



    $('input').on('ifToggled', function (event) {

        $("#outputbythis").text($(this).val())

        $("#outputbyname").text($("input[type=radio][name=test]").val())

    });

});

那是因为选择器将 return 一个数组。

jQuery(document).ready(function ($) {

    $('input').iCheck({
        checkboxClass: 'icheckbox_flat-green',
        radioClass: 'iradio_flat-green'
    });



    $('input').on('ifToggled', function (event) {

        $("#outputbythis").text($(this).val())

        $("#outputbyname").text($("input[type=radio][name=test]:checked").val())

    });

});

这应该有效